Page 1 of 1

External JavaScript Headache

Posted: Tue Feb 17, 2004 10:36 am
by starsol
I've found lots of tutorials on including external JavaScripts but none of them addresses my problem, and as far as I can tell I'm doing everything correctly, so I'm putting this to all those with a bit more JavaScripting experience than myself as I imagine I've probably overlooked something very simple.

If I put some JavaScript in the head of a HTML page, such as:

Code: Select all

<script language='JavaScript'>
<!--
function jsopen(URL) &#123;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=425,height=250');");
&#125;
// -->
</script>
and I put this in the actual HTML:

Code: Select all

<a href="javascript:jsopen('/path/to/a/file.php')">Link</a>)
everything works fine.

But if I create the following file:

Code: Select all

<!--
function jsopen(URL) &#123;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=425,height=250');");
&#125;
// -->
save it as js.js, then call it by:

Code: Select all

<script language='JavaScript' src='js.js' type='text/javascript'>
in the head of the page - the same link doesn't work.

Can anyone tell me where I'm going wrong?

Thanks for your time.

Posted: Tue Feb 17, 2004 10:55 am
by JayBird
try this in your head tag, not 100% sure if you actually need to close the script tag, but this is always how i have done it.

Code: Select all

<script language='JavaScript' src='js.js' type='text/javascript'></script>
Mark

Posted: Tue Feb 17, 2004 12:09 pm
by Illusionist
try leaving out language='JavaScript'

Posted: Wed Feb 18, 2004 3:41 am
by starsol
Cheers, it was that </script> was needed.