How can I prevent JavaScript in an iFrame to access properties of the outer site, even if the iFrame's content comes from the same origin?

后端 未结 2 702
挽巷
挽巷 2020-12-21 00:45

Basically I want to have an iFrame which always restricts it\'s content as if it comes from a different domain, even if the content comes from the same origin.

Is th

2条回答
  •  天涯浪人
    2020-12-21 01:33

    The best solution is probably to use the HTML5 sandbox attribute on the iframe, which (by default) explicitly disables both scripting and same-origin access to the parent DOM.

    Good introduction at http://msdn.microsoft.com/en-us/hh563496.aspx

    As of Dec 2012, this seems to be supported on most current browsers.

提交回复
热议问题