Drive around a browser iframe over multiple page requests using a postMessage bus.
In the page(s) you want to drive around, insert the
proxy.js file from this distribution:
$ browserify proxy.js -o proxy_bundle.js
Ideally you could insert this script tag at the top of all text/html responses with a custom proxy but putting the tag in yourself manually works too.
Now you can boss those other pages around, like this:
var schoolbus = ;var domready = ;;
which when run against our particular pages will log the following output:
var schoolbus =
Return a new bus starting at
Optionally, you can specify some variables
vars which will be sent over the
postMessage bus using
so you can send circular objects and callbacks.
Just don't try to send dom nodes.
If you specify a callback
bus.next(cb) will register a listener
when the page contents become available.
Register a callback
cb for the next available page transition.
Each transition fires a registered callback FIFO, so you can build up a queue of callbacks to script what happens when multiple pages are visited.
cb will be stringified with
.toString() and evaluated in the new page
context, but with the variables bound when
schoolbus() was called.
Drive the bus to
Fired when a remote page loads in the iframe that has the proxy.js script.
loc is a copy of the page's
With npm do:
npm install schoolbus
proxy.js with browserify and drop it into the pages you want to