html5怎样进行跨域通信


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

export default class Messager {

    constructor(win, targetOrigin) {

        this.win = win;

        this.targetOrigin = targetOrigin;

        this.actions = {};

        window.addEventListener('message', this.handleMessageListener, false);

    }

  

    handleMessageListener = event => {

        if (!event.data || !event.data.type) {

            return;

        }

        const type = event.data.type;

        if (!this.actions[type]) {

            return console.warn(`${type}: missing listener`);

        }

        this.actions[type](event.data.value);

    }

  

    on = (type, cb) => {

        this.actions[type] = cb;

        return this;

    }

  

    emit = (type, value) => {

        this.win.postMessage({

            type, value

        }, this.targetOrigin);

        return this;

    }

  

    destroy() {

        window.removeEventListener('message', this.handleMessageListener);

    }

}

相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

H5的所有元素及基本语法归纳

H5中视频与音频标签和进度条如何使用

H5怎样实现拖放功能

以上就是html5怎样进行跨域通信的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

HTML5与html区别是什么

HTML5 source标签怎么用?HTML5 source标签属性介绍

HTML5 canvas如何实现代码流瀑布?(附代码)

HTML5转义实体字符的使用详解

HTML5中的progress元素的详细介绍及兼容性处理

前端必看h5 meta小结

如何通过HTML5触摸事件实现移动端简易进度条

基于HTML5陀螺仪实现移动动画效果

HTML5打开本地app应用的示例代码

HTML5 web worker的介绍(附示例)

更多相关阅读请进入《HTML5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...