How to make links break out of iframe when you only control the iframe page (not the framed pages)?

23,270

Solution 1

No solutions.

The only way to get a link to open in the top frame is to have access to the link itself. As you observed, the same origin policy prevents JS from outside the frame accessing it.

Solution 2

Try target=_top That should open the page in the full body of the window.

Share:
23,270
Admin
Author by

Admin

Updated on August 01, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a site that displays other sites through an iframe on certain pages. It does this in order to display a toolbar that is relevant to the reader (like Facebook and Owly does). However, when the user chooses to leave the original site I want the bar to go away. As you might gather, I don't control the sites in the iframe, and they're on another domain than the iframing page.

    I tried target="_parent" on the <iframe>, no luck. Then I tried various scripting solutions, but they all fail due to the same domain restriction. My last try was to have a timeout check for changes in the iframe URL, but iframe.contentWindow.location.href is restricted when page is on another domain (unlike the object iframe.contentWindow.location which I found a bit weird).

    Any solutions to this problem? I know iframes aren't the hottest thing around, but they do the job in this case.

  • Quentin
    Quentin almost 15 years
    Christian said "I don't control the sites in the iframe", so how could he add that?
  • MystikSpiral
    MystikSpiral almost 15 years
    You said you had tried target=_parent, so forgive me. You could try embedding the HTML base tag (<base target=_top />). It goes in the head of the doc so you would have to intercept the HTML and add it using Javascript for each iFrame doc.
  • Quentin
    Quentin almost 15 years
    He said the HTML is on a different domain. It can't be intercepted with JS.