How can I sandbox untrusted user-submitted JavaScript content?
问题 I need to serve user-submitted scripts on my site (sort of like jsfiddle). I want the scripts to run on visitors browsers in a safe manner, isolated from the page they are served on. Since the code is submitted by users, there is no guarantee it is trustworthy. Right now I can think of three options: Serve the user-submitted content in an iframe from a different domain , and rely on the same-origin policy. This would require setting up an additional domain which I'd like to avoid if possible.