Can I get ifame links openin a new window?
February 24, 2008 5:59 PM
Subscribe
External web page being displayed in an Iframe. How can I make the links in the displayed web page open in a new window OR make it such that clicking anywhere on the iframe opens the displayed external page in a new window. Could get a tad NSFW inside.
1) I do not have access to the source code of the external pages.
2) I am authorized to display them anywhere and in any manner I choose.
There is a special code in the links of the pages that when someone clicks a link in one of these pages, it is tracked by the external pages owner and I get credit if the user purchases something.
I have cobbled together a way to display, via iframe and javascript code, a random page (of several thousand which changes upon every reload) from the websites of which I am affiliate at the bottom of my own website's pages.
The problem is that when a link is clicked it opens within the iframe itself, and that makes it extremely difficult to navigate the external site, and in some browsers, the clicked link wont display at all in the iframe.
What i need is that when a user clicks that link, the link OR the page the link lives on, opens in a new window. Then all problems are solved.
One consideration: I cant have MY links to MY content which are on the page open in new windows. Just whats in the iframe.
Thoughts, hivemind?
Thanks in advance!!!
P.S. I'll be on for an hour or so if I can provide more info I will, but i think i covered it pretty well :-)
posted by sandra_s to computers & internet (8 comments total)
Two ideas:
1) periodically poll the src attribute in javascript to see if it changes. If it does, launch that source in a new window and reset the source to the origional location. That would be pretty irritating for users.
2) Write a pass through script that reads the page off the remote server, adds target="_new" attributes to all of the hrefs in the page, then gives sends it on to the user. So they would go to a URL like http://mysite/redir.php?url=http://theirsite/wherever.
Both would be a lot of work. #1 might be easier then #2, but I'm not sure if it would actually do what you want.
That's off the top of my head, there may be a better way to do this.
posted by delmoi at 6:17 PM on February 24