Search code examples
htmlcssiframehtml-target

Opening a specific link outside the iFrame


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.


Solution

  • 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>