Return to Snippet

Revision: 2501
at March 22, 2007 04:50 by 1man


Updated Code
function doStandardsCompliantExternalLinks() {
	if (!document.getElementsByTagName) {return;}
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") {// for example: title="Download Adobe Reader" rel="external"
			anchors[i].target = "_blank";
			anchors[i].title += " - Opens in new window";
		}
	}
}

Revision: 2500
at March 8, 2007 03:11 by 1man


Initial Code
function doStandardsCompliantExternalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {// for example: title="Download Adobe Reader" rel="external"
			anchor.target = "_blank";
			anchor.title += " - Opens in new window";
		}
	}
}

Initial URL

                                

Initial Description
This function allows you to open a new window, without using any inline Javascript. Simply add rel="external" to the link you wish to open in a new window.

Initial Title
Standard Compliant Way to Open A New Page Function

Initial Tags
javascript, window, DOM

Initial Language
JavaScript