How to run script on different context to the current window?

Code:

var dataScript = '$("#foo").append("$ and #foo exists!")';

Suppose we have some library loaded (ex: $jQuery) in our document, if we run this

eval(dataScript); //This will work and adds a text to our current document

I want:

eval(dataScript); //$ is undefined (Maybe you're in another context?)

I currently use JSJS library http://jterrace.github.io/js.js/ but this library is necessary to manually add many essential items such i.e window, document, etc ...

There will be some method to run script without interacting with the current page?. There should also be communications between the current window and the new context.

+

Upvotes: 0

Views: 171

Answers (1)

user3844028
user3844028

Reputation:

You can use Iframe with the sandbox option, that's the best solution to me http://www.w3schools.com/tags/att_iframe_sandbox.asp

Upvotes: 1

Related Questions