Skip to content Skip to sidebar Skip to footer

Multiple Javascript Interpreters In A Single Browser Tab

Is it possible to have multiple javascript interpreters(engines) running in a single tab of a browser window? How? I have looked into iframe but have not been able to invoke a sepa

Solution 1:

You may want to look at Web Workers. These partition execution of Javascript, but have a very defined way of interaction.

Solution 2:

Each distinct page has its own global environment. Related pages are linked in various ways (window.parent, the frame elements, etc). If a parent page includes a secondary page as the contents of an <iframe> tag (or in an old-style frameset setup, which I haven't done in well over a decade :-) then the pages in frames each have their own distinct window object, and their own copies of frameworks, tools, etc.

When you do something like document.getElementById("whatever"), that's limited to the global context from which it's called. Similarly, each frame has its own JavaScript environment, with its own distinct copy of the various JavaScript "native" constructors. That is, "Array" in one frame is a distinct object from "Array" in another frame.

@Jarrod N's mention of web workers may also be of great interest to you.

Solution 3:

As Pointy said, each distinct page has its own global environment. So iframe also has its own Javascript environment.

My tests with iframe were failing because I was not waiting for the Javascript/webpage in the iframe to get fully loaded, before invoking it from the main page.

p.s. WebWorkers was slightly complicated and has less support for what I wanted for my project. It looks to be a good solution for future projects though.

Post a Comment for "Multiple Javascript Interpreters In A Single Browser Tab"