Preventing child iframe from “breaking out of frame”

前端 未结 4 433
轻奢々
轻奢々 2020-12-05 15:54

I\'m doing some simple web integration work which I\'m accomplishing through use of an iframe. My main window has some javascript which interacts with my server to redirect

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 16:25

    This is my first post so don't trash me if it doesn't work, but this fix seems to work for me in IE. Add security="restricted" to your frame.

    example:

    
    

    Edit: I found a better solution. That doesn't block scripts and doesn't require javascript. Try using sandbox="..."

    • allow-forms allows form submission
    • allow-popups allows popups
    • allow-pointer-lock allows pointer lock
    • allow-same-origin allows the document to maintain its origin
    • allow-scripts allows JavaScript execution, and also allows features to trigger automatically
    • allow-top-navigation allows the document to break out of the frame by navigating the top-level window

    Top navigation is what you want to prevent, so leave that out and it will not be allowed. Anything left out will be blocked

    ex.

    
    

提交回复
热议问题