link to external *.js file

They have: 3 posts

Joined: May 2000

I've got an html file like this:

<script language="javascript" src="test.js">
</script>

And a test.js is exactly like this:

<script language="javascript">
location.href="www.yahoo.com";
</script>

It doesn't work.

I'm just wondering if I use the word SRC is correct or not? Is there anything else I should pay attention to?

Thanks

AndyB's picture

They have: 344 posts

Joined: Aug 1999

So when your external script loads you'll have the script tags inside the script tags.

Change your test.js file to the 'all' of the script except the opening and closing lines.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

As AndyB said, you do not put the script tags within a js file. Nor any html code. The only thing allowed is straight javascript -- variables, functions, comments, keywords, etc.

Vinny

------------------
my site:GrassBlade: cut&paste javascript
moderator at:The Javascript Place
Javascript City

Where the world once stood
the blades of grass cut me still

They have: 67 posts

Joined: Aug 1999

Hi ChanhVu,

Change the inside of your .js file to this and it will work fine for you.

<!-- Begin
location.href="http://www.yahoo.com";
//-->

You can also easily write html using .js files by using the document.write method. eg.

<!-- Begin
document.write("<font face='Arial,Helvetica' size=-1>");
document.write("<b>");
document.write("<a href='http://www.a1javascripts.com'>A1 JavaScripts</a>");
document.write("</b>");
document.write("</font>");
//-->

Also images:

document.write("<a href='http://www.xxx.com/'><img SRC='xxx.gif' ALT='xxx' BORDER=0 height=31 width=88></a>");

However, calling things from .js files does slow down page loading.

Hope this helps you.
Good luck

Ian

------------------
Webmaster A1 JavaScripts
A1 JavaScripts
Web Development - Big Resources Inc
BIG Resources.com

Webmaster A1 JavaScripts
A1 JavaScripts
Web Development - Big Resources Inc
BIG Resources.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.