Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

pass events between unrelated browser windows

branch: gh-pages

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore forgot .gitignore, as always, damn July 09, 2011
Octocat-spinner-32 README.md
Octocat-spinner-32 index.html
Octocat-spinner-32 jquery-1.6.1.min.js
Octocat-spinner-32 jquery.browserEvent.js
Octocat-spinner-32 jquery.store.js
Octocat-spinner-32 json2.js
Octocat-spinner-32 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.