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怎样进行跨域通信的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

微信的h5页面调用第三方位置导航

自定义实现可以播放暂停、进度拖拽、音量控制及全屏的h5播放器

如何解决HTML5微信播放全屏问题的方法

分享几款炫酷的HTML5实现的图片特效

HTML5实现画虚线效果代码

HTML5手机触屏touch事件的详细介绍

了解一下HTML5中新增加的标签

如何利用HTML5 canvas旋转图片?(实例演示)

如何让HTML5手机端弹出遮罩菜单特效

HTML5动画有什么用?

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




打赏

取消

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

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

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

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

评论

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