1

I have a specific part of my website that runs in an iFrame. Now in the webpage that is run inside the iFrame, I specified <base target="_parent" /> for all links, and they all open inside the iFrame(so if I would link to my main website home page, it would open inside the iframe). Now I want one specific link to open outside of the iframe and inside of the normal parent webpage.

How do I force that one specific link to do that? Tried target="_blank" but still opens inside the iFrame.

luchaninov
  • 6,792
  • 6
  • 60
  • 75
DextrousDave
  • 6,603
  • 35
  • 91
  • 134

4 Answers4

4

If you are using JavaScript:

        parent.document.location = "http://www.google.com"

And if you are using HTML:

        <a href="http://www.google.com" target="_top">Google</a>
Community
  • 1
  • 1
Devaroop
  • 7,900
  • 2
  • 37
  • 34
2

I've come across this solution a while back and I've been using it ever since. Force the link with a Javascript function:

<script type='text/javascript'>
 function newWindow(){
   top.location.href = 'http://yourURL';};
</script>
<a href="javascript: newWindow();">YourLink</a>
Dexter Schneider
  • 2,494
  • 7
  • 25
  • 28
0

Add this to the link onclick="window.location = 'url.html';"

shahbaz
  • 372
  • 1
  • 3
  • 18
  • Thanks for your answer, but it does not working. Tried with both setting the href='url.html' and without the href='url.html'...Any other suggestions? – DextrousDave Jun 14 '12 at 12:37
  • 1
    See this http://stackoverflow.com/questions/1037839/how-to-force-link-from-iframe-to-be-opened-in-the-parent-window – shahbaz Jun 14 '12 at 13:32
  • Generally it is inadvisable to put inline JavaScript in your HTML. Better practice would be to have this click event handler attached by a script after the DOM object (the link) has been loaded. – saluce Jul 15 '12 at 05:01
0

When I make menus I make an iframe inside my index.html:

<div id="nav">
     <iframe frameBorder="0" height="35px" width="950px" src="navframe.html"></iframe>
</div> 

Then in the navframe.html these are my buttons:

<button type="button" onClick="window.parent.location='index.html'">
Home</button>

<button type="button" onClick="window.parent.location='contact.html'">
Contact</button>

that tend to work