简体   繁体   中英

iframe links to not open in new window

i is possible to force iframe to open links inside iframe window . means when i click link in iframe it opens link in same window but not in iframe . i want that when i click link it should open link in same iframe . i don't want to edit some code in links cause there are too many links so i can;t edit that.???

so it is possible to make so this thing by changing code in i frame or using javescript in i frame ???

<iframe src="demo_iframe.htm" width="200" height="200"></iframe>

This code works good for me, your iframe must contain a page from the same domain, and don't froget to set the id of your iframe to id="iframe"

$(document.getElementById('iframe').contentWindow.document.getElementsByTagName("a")).click
(
   function()
   { 
        document.location.href=$(this).attr('href'); 
   }
);

The easiest way to do this is using the parent attribute on the link inside your demo_iframe.htm page. For example:

<a target="_parent" href="http://www.example.com">link</a>

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM