Posted By

alvaroisorna on 11/20/06


Tagged

javascript sandbox


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

rnrleachryan
vali29
umang_nine
wirenaught


Ajaxian » Sandboxing JavaScript with iframes


 / Published in: JavaScript
 

URL: http://ajaxian.com/archives/sandboxing-javascript-with-iframes

  1. // create an <iframe>
  2. var iframe = document.createElement("iframe");
  3. iframe.style.display = "none";
  4. document.body.appendChild(iframe);
  5.  
  6. // write a script into the </iframe><iframe> and create the sandbox
  7. frames[frames.length - 1].document.write(
  8. "<script>"+
  9. "var MSIE/*@cc_on =1@*/;"+ // sniff
  10. "parent.sandbox=MSIE?this:{eval:function(s){return eval(s)}}"+
  11. "<\/script>"
  12. );

Report this snippet  

You need to login to post a comment.