0.0.1 • Published 8 years ago
cross-browser-tab v0.0.1
跨浏览器tab通信:
使用:
npm install cross-browser-tab --save
script使用:
- POST
返回示例
var cross = new CrossBrowserTab({
keys: ['room', 'logout'],
listener: [fn1, fn2]
})
function fn1 (event) {
console.log('fn1')
console.log(event)
}
function fn2 (event) {
console.log('fn2')
console.log(event)
}
// 某个tab发出通知
cross.emitter('room', 'join_room')
// 其他tab内的fn1函数回调运行,打印:
{
key: "room"
newValue: "join_room"
oldValue: "sdsdsd"
tabName: "15204299093473108"
url: "http://172.28.44.79/raojianbing/test/cross-browser-tab/localstorage-2.html"
}
new参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| keys | array | 字段名 |
| listener | array | 对应字段发生变化,回调函数,该回调得到一个参数 |
tab的回调参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| key | string | 字段名 |
| newValue | string | 该字段的新值 |
| oldValue | string | 该字段的老值 |
| tabName | string | 发出此通知的那个tab的名字 |
| url | string | 发出此通知的那个tab的url地址 |
备注
- 更多返回错误代码请看首页的错误代码描述
0.0.1
8 years ago