Search code examples
htmlhreftarget

How do I use a target = blank for <a> tags in iframe?


My page is an iframe in the main page. And hung a link like <a href="http://www.google.co.kr" target="_blank"> google </a> in an iframe. However, the links do not operate. target = '_ self' is a well operation, target = '_ blank' is not operated. It works fine on the main page.

Why would it?


Solution

  • I'm sure the issue have something to do with the sandbox attribute. It seems that you can add the attribute "allow-top-navigation", change the link to 'target=_parent' and should works.

    Here is a little bit of documentation from the MDN:

    About the sandbox attr:

    • allow-top-navigation: Allows the embedded browsing context to navigate (load) content to the top-level browsing context. If this keyword is not used, this operation is not allowed.