Coder Social home page Coder Social logo

messenger's Introduction

Messenger


Build Status

跨域 Iframe 通信解决方案,兼容主流和 IE 系列浏览器。


Usage

父页面

// 初始化父页面的信使
var messenger = new Messenger('parent', 'MessengerProject');

// 绑定子页面 iframe
messenger.addTarget(iframe1.contentWindow, 'iframe1');
messenger.addTarget(iframe2.contentWindow, 'iframe2');

// 给子页面发消息
messenger.targets['iframe1'].send('发给子页面1的消息');

// 或者给所有子页面发消息
messenger.send('发给所有子页面的消息');

子页面

// 初始化子页面的信使
// 注意,第二个参数 `MessengerProject` 必须和父页面的信使保持一致,
var messenger = new Messenger('iframe1', 'MessengerProject');

// 绑定父页面
messenger.addTarget(window.parent, 'parent');

// 给父页面发消息
messenger.targets['parent'].send('发给父页面的消息');

感谢

本组件源码来自 https://github.com/biqing/MessengerJS

文档亦可参考 biqing/MessengerJS

messenger's People

Contributors

afc163 avatar antife-yinyue avatar bitdeli-chef avatar dafeizizhu avatar eyunfeis avatar lepture avatar lifesinger avatar lizzie avatar popomore avatar sorrycc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.