Welcome to WebmasterWorld Guest from 54.160.221.82

Forum Moderators: open

Message Too Old, No Replies

External JS question

Little help with external JavaScript please...

     
5:54 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Hi everone,

I'm putting a lot of JS in an external file and calling it like this:

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

So, firstly: Is that the correct way to do it?

Secondly, I need to call some JS from another site. Can I do that from within my external JS? And of course, how do I do it?

In the code I'm working on it's just another <script src=> jobbie, I need to be able to do that from the external JS...

Many thanks...

Nick

gsx

6:05 pm on Nov 3, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 20, 2002
posts:603
votes: 0


Yes, that is the correct way, although you may want to add the language="JavaScript" (I think that is what it should be, you may need to double check), in case the browsers default scripting is something other than JavaScript (I don't know of any, but there could be some).

You can include other JavaScript from other sites by giving the full address ie. [?.com...]

Call from external? You mean as a library? You can include both, i.e. include the external first (as a function library), then include the internal ones that call the functions in the external.

6:22 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Thanks.... I'm kinda with you ;)

So in my evternal file how would it look to call another script from another site?

Nick

6:26 pm on Nov 3, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I think you might have to have two script statements, I don't know if it will do it from within the external js file.

All I can say, slap the script tags for the other site into the external and test it. If it doesn't work put two sets of script tags on the original page.

6:30 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member macguru is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 30, 2000
posts:3300
votes: 0


Pardon my curiosity Nick_W, but why do need to do that?
6:45 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


hehe, it's an affiliate order form. I want to hide the JS call to an outside site from casual glance....

Nick

7:54 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member macguru is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 30, 2000
posts:3300
votes: 0


Good idea! Thanks for sharing.
7:59 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


Hey, Nick. The attribute language="JavaScript" was introduced back when Netscape first introduced javascript -- but it is now deprecated in HTML 4.01. In fact, it's not supported at all in strict XHTML.

The recommended attribute is type="text/javascript". If you want deep backward compatibility, you can use them both:

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

11:14 pm on Nov 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Right, thanks everyone ;)

Nick