I am using some code I found on the internet to make all my external links in a new window. Also, I want to make these links gray. I think I once heard you coulden't change link colors at all once a page was loaded, but I may be wrong. In any case, it won't work. Here is my code:

this.blankwin = function(
{
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj)
	{
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 &&  href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj)
	{
		obj.target = "_blank";
		obj.className = "external";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};


// script initiates on page load. 

this.addEvent = function(obj,type,fn)
{
	if(obj.attachEvent)
	{
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} 

	else
	{
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",blankwin);
a.external:hover
{
    color: Gray;
    text-decoration: underline;
}

Edit: Now I find I can't make them open in a new window either.

1) You're missing an ending ) on the first line of your JS

2) "Gray" isn't a safe CSS color, use #ccc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.