We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

alvaroisorna on 11/20/06


Tagged

javascript sandbox


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

rnrleachryan
vali29


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.