Giter Site home page Giter Site logo

messenger's Introduction

Messenger


Build Status

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


API

target selector

收发信息的目标页面。

onmessage function

接受消息的处理函数,第一个参数为收到的信息。

方法

send function

使用 send 方法来给目标页面发送信息,接受一个 string 或 纯 object 参数(IE 8/9 不支持)。

messenger.send('The Message.');

messenger.send({ a: 'b' });

最佳实践

父页面

// target 参数为 iframe
var messenger = new Messenger({
    target: '#iframe',
    onmessage: function(msg) {
        console.log(msg);
    }
});
// 给子页面发消息
messenger.send('发给子页面的消息');

子页面

// target 参数为 parent
var messenger = new Messenger({
    target: parent,
    onmessage: function(msg) {
        console.log(msg);
    }
});
// 给父页面发消息
messenger.send('发给父页面的消息');

感谢

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

messenger's People

Contributors

afc163 avatar eyunfeis avatar lifesinger avatar popomore avatar

Watchers

 avatar  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.