External JavaScript Headache

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
starsol
Forum Newbie
Posts: 24
Joined: Thu Jul 31, 2003 8:30 am
Location: Norfolk, England.
Contact:

External JavaScript Headache

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try leaving out language='JavaScript'
starsol
Forum Newbie
Posts: 24
Joined: Thu Jul 31, 2003 8:30 am
Location: Norfolk, England.
Contact:

Post by starsol »

Cheers, it was that </script> was needed.
Post Reply