Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
pass events between unrelated browser windows
JavaScript
Branch: gh-pages

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.md
index.html
jquery-1.6.1.min.js
jquery.browserEvent.js
jquery.store.js
json2.js
screen.css

README.md

jQuery browserEvent

$.browserEvent() was intended to allow passing messages between unrelated browser windows. So if you open a page twice, the two pages could synchronize their states. The plugin was written before any browser had SharedWorker implemented - which makes message passing possible natively. But at this time only Chrome supports SharedWorkers.

Have a look at the demo to see it in action.

Basic concept

Use localStorage as the central data exchange point. This of course means repeatedly reading and writing to that data point. (Race conditions are possible, but unlikely.)

Dependencies

  • jQuery 1.6 (was originally written on 1.4.2)
  • jQuery.store (localStorage interface)
  • JSON2 (for older Internet Explorers)

Usage


$(function(){
    // initialize storage
    $.storage = new $.store();
    $.storageWindow = new $.store('windowName');
    // let us know when we're ready
    $.browserEvent.ready = function() {
        window.console && console.log("$.browserEvent is ready for business");
    };
    // init browserEvent
    $.browserEvent
        // callback for list of connected windows
        .bind('browserWindows', handleWindowUpdate)
        // callback for proprietary message event
        .bind('message', handleMessageevent)
        // Run Forrest, Run!
        .init( $.storage, $.storageWindow );
    
    // send event to specific window (ident passed to handleWindowUpdate for registration)
    $.browserWindow.trigger('message', "some data to send", windowIdent);
    
    // send event to all windows
    $.browserWindow.trigger('message', "hello my friends");
    
    // add other events
    $.browserWindow.bind('foo', handleFooEvent);
    $.browserWindow.trigger('foo', "Bar!");
});

License

$.browserEvent is published under the MIT license.

Something went wrong with that request. Please try again.