Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

noelister

macrumors 6502
Original poster
Jan 15, 2005
275
0
Hey everyone,

I am trying reference an external JavaScript file on a page I am working on and Safari seems to have problems with it. However, Firefox displays the file fine... Could someone tell me what I am doing wrong?

---HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1 TRANSITIONAL//EN"
"http://www.w3.org/TR/xhtml11/DTDxhtml11.dtd">
<html>
<head>
<title>Example</tilte>
<script type="text/javascript" src="example.js"></script>
</head>
<body onload="process()">
Hello there, here's a list of colors being displayed with an external JS file: <br />
<div id="myDivElement" />
</body>
</html>

---END HTML

---JS FILE

function process()
{
//create the HTML code with JavaScript
var string;
string = "<ul>"
+ "<li>Black</li>"
+ "<li>Red</li>"
+ "<li>Green</li>"
+ "</ul>";
//obtain the a reference to the <div> element on the HTML page
myDiv = document.getElementById("myDivElement");
//Add content to the <div> element "myDivElement on the HTML page
myDiv.innerHTML = string;
}

---END JS FILE

Thanks for any and all help,
N
 
Try this:

<script language="JavaScript" type="text/javascript" src="example.js"></script>
 
zim said:
Try this:

<script language="JavaScript" type="text/javascript" src="example.js"></script>

That did not work... The page still renders blank in safari...:confused:
 
Ok I uploaded the html and js to my site to test it out.

If there is no text showing up at all, then perhaps the problem could be this?...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1 TRANSITIONAL//EN"
"http://www.w3.org/TR/xhtml11/DTDxhtml11.dtd">

You have a line break there. Perhaps Safari has problems recognizing this as valid code maybe, though netscape just seemed to not care and load the page fine. So if this is the case, make sure you edit your code so that this is 1 line and not 2.


EDIT: Ok I didn't think I guess, since it does work in another browser, then there couldn't be problems with the js location or permissions, so I just deleted that idea.. still it could be the doctype problem above.
 
Thanks tag and zim. I found the problem. It was a typo, the closing title tag was misspelled "</tilte>". Every thing seems to be working as it should. I guess firefox ignores and or fixes these kind of things...:confused: Anyways thanks again for the quick responses.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.