Standard browser scripts are very restricted as to their input: they mostly operate on the HTML in the current web page, and have no native means of accessing other data. HTML itself however has a couple of mechanisms for loading external documents, which can be used as proxies for a script.
This loads text from an external file into an invisible
iframe
object, then with JavaScript gets the text from the
object, processes it, and displays it in a different part of the web page.
HTML could also be similarly obtained as text or traversed as an object tree.
At the time the main document is loaded, any child iframe
referring to an external document is empty. This is because if the external
document takes time to download, the rest of the document should be
rendered first.
The onload
attribute of the iframe can be set to execute a
function when the document arrives. So the trick is to set a timer to wait
until this event fires, then to get and render the iframe contents.