Giter Club home page Giter Club logo

framebus-sw's Introduction

Framebus-sw

Framebus-sw, a forked project from Framebus 5.1.2, allows you to easily send messages across frames (and iframes) with with either broadcasting to all or only to the especified frame.

Usage references: Framebus (https://github.com/braintree/framebus)

Change

Added broadcastMode to FramebusOptions.

Option broadcastMode decided which window the message will be post to. Options such self, parent, children will verify window origin with target origin before post message, so that can avoid the error throw from postMessage when it does not.

type FramebusOptions = {
  origin?: string, // default: "*"
  broadcastMode?: string, // default "all
  channel?: string, // no default
  verifyDomain?: (url: string) => boolean, // no default
};

If Verify Origin is No, it will throw error to web console when window origin does not match with target origin.

Options Verify Origin Description
all No Broadcast the message to all iframes from the top to down.
self Yes Only post the message back to window itself
parent Yes Only post the message to the window.parent.
top No Only post the message to window.top.
children Yes Post to all accessible iframe in the window excluded the window itself.

Examples

    const Framebus = require('framebus-sw');

    // default bus instance
    const bus = new Framebus();
    const defaultBus = new Framebus({ broadcastMode: 'all' });

    // bus instance only posts messages to itself
    const selfBus = new Framebus({
        origin: location.origin,
        broadcastMode: 'self'
    });

    // bus instance only posts messages to its verified parent
    const parentBus = new Framebus({
        origin: 'http://parent_origin.com'
        broadcastMode: 'parent'
    });

    // bus instance only posts messages to the verified children
    const childrenBus = new Framebus({
        origin: 'http://children_1.com'
        broadcastMode: 'children'
    });

framebus-sw's People

Contributors

crookedneighbor avatar braintreeps avatar mrak avatar jeffcarp avatar dependabot[bot] avatar blutorange avatar evanhahn avatar jplukarski avatar lilaconlee avatar quinnjn avatar rumiljonov 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.