Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link Target

Status
Not open for further replies.

LOW

Programmer
Sep 27, 2000
45
US
I'm attempting to put some logic into a dynamically generated page with links. For example, if a link contains 'pubtext' in the url, I want the link to open in another window (target=_blank"). All other links to open in the same window (target="_self"). I"m just not sure how to accomplish this. Any ideas would be much appreciated.
 
Code:
window.onload=function(snd){
	var links = document.body.getElementsByTagName("a");
	for(link in links){
// check if link.href!=null
	if(link.href.toLowerCase().indexOf("pubtext")!=-1){
			link.target="_blank";
		}else{
			link.target="_self";
		}
	}
}

For better debugging please use firefox with the firebug plugin.



Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top