pass events between unrelated browser windows
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

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


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


	// 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
		// 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!");


$.browserEvent is published under the MIT license.