tags:

views:

281

answers:

3

Hi if I have frames setup on a page, is there a way to force all links in a child frame to open in a new window('blank') rather than 'self'?

I have no access to the page that I have in my frame, sometimes the links open new pages sometimes they just transfer to a totally new page. I want to keep some consistency by making all links open in new pages. Thanks.

A: 

Don't use frames.

Or load them in using a HTTP object (there's plenty in a lot of server-side languages), modify the links using regular expressions to point to '_blank' instead' and then put them on your page.

Alternatively, you might be able to use the DOM:

nodeLink = document.getElementById("alink");
nodeLink.setAttribute("target", "_blank");
Rushyo
I will give this a try, thanks.
A: 

What am I missing when I respond with the following?

If you can't change the page in the frame, you're not going to change its behavior.

lance
I was just asking if there was some way I could use javascript to manipulate the frame and what/how it is loaded.
Got it. nickf's solution is good, but I do believe you're *not* able to "modify the DOM of external pages". Hence my comment about "you can't change the page in the frame", as you don't own it.
lance
+1  A: 

You could use some javascript:

var links = document.getElementsByTagName('a');
for (var i = 0, l = links.length; i < l; ++i) {
    links[i].target = '_blank';
}

You'll just have to get a reference to the document in your frame (sorry, it's been a long time since I've worked with frames). From memory it's something easy like frame.document

I'm not positive that you can modify the DOM of external pages, but it's worth a shot.

nickf
I will give this a try, thanks.