Incompatible javascript files?

Keep in mind I am using an XHTML 1.0 Strict DTD.
I created two external js files. One is used to open my contact page, which opens in a separate window and is resized, without scrollbar, or location, etc… The second file is meant for any links I want to open in an external window. Both files work independently, but when the links to each file are both present (In the head of the HTML doc) the one underneath always wins, by default I suppose. Is it possible to have two javascripts trying to do two very similar things?

Here is the code for the contact page:

function newWinLinks() {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].className == "contactWin") {
			document.links[i].onclick = newWindow;
function newWindow() {
	var contactWindow ="contact.html","contactWin","toolbar=no, location=no, scrollbar=no,resizable=no,width=378,height=590");
	return false;

window.onload = newWinLinks;

…and the link file:

<script type="text/javascript" src="../js/contactLink2.js"></script>

Here is the code for the external links:

function externalLinks() {  
 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") = "_blank";  

window.onload = externalLinks;

…and the link file:

<script type="text/javascript" src="js/external.js"></script>

I am pretty new at web design, so I’m sure I’m missing something that may be obvious to someone else.

I believe the problem is windows.onload can only load a single thing, so you are overriding the first onload with the second one. I’m not an expert of this however.

There might be a sitepoint article mentioning a solution, using another function to do the loading.

You definitely need to combine the onload statements into one. The following is the simplest replacement.

window.onload = function() {newWinLinks(); externalLinks();}

The XHTML doctype will not make any difference unless you are actually serving the page as XHTML instead of HTML. If so then many of the other statements may not work either since you are using the HTML version of the DOM calls. Presumably you are serving as HTML though as Internet Explorer doesn’t support XHTML at all.

Thank you “felgall!” That was all it needed. I really appreciate it!