Author |
Message |
GXEman
Junior WebHelper
Joined: 07 May 2003
Posts: 27
Location: Athens, GA
|
Posted:
Mon May 12, 2003 5:19 pm (20 years, 11 months ago) |
|
Is there a way to create an external javascript and insert it into a page? I have a huge javascript that displays a random quote on my homepage and wondered if I could do something external like you can do with style sheets. |
________________________________ Freshfemi.net
Too Cool For a Dot Com |
|
|
|
verto
Senior WebHelper
Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA
|
Posted:
Mon May 12, 2003 5:37 pm (20 years, 11 months ago) |
|
Yes, very easy. But I suggest you also try searching for a few JavaScript tutorials:
link: Google Results for 'javascript external script'
...as a decent tutorial will explain the in's and out's much better than will fit in this forum reply:
Anyway, here's the basic form:
Code: | <SCRIPT language="JavaScript" SRC="http://www.pageresource.com/jscript/jxt1.js"></SCRIPT> |
...and don't forget to take the HTML tags out of your external file (<SCRIPT> and </SCRIPT>). |
________________________________ >>>>>>>>>>>>>
GENERAL DISCLAIMER:This disclaimer may be void where null in all cases unless explicitly not unprohibited or (p)re-exclusively assigned by sufficient presedimentation on behalf of every non-interested party to wit (or so it was said).
:::
.: :. . : :....: :.: .: :. verto .: :. . : :....: :.: .: :. |
|
|
|
GXEman
Junior WebHelper
Joined: 07 May 2003
Posts: 27
Location: Athens, GA
|
Posted:
Mon May 12, 2003 7:47 pm (20 years, 11 months ago) |
|
Thanks for the reply, but I still have a problem. Please bear with me, I'm an idiot.
I went to http://www.pageresource.com/jscript/jxtern.htm and followed the instructions.
I copied and pasted their example javascript into a notepad file and saved it as a "jxt1.js"
Code: | function a_message()
{
alert('I came from an external script! Ha, Ha, Ha!!!!');
}
|
Then I created an HTML file:
Code: | <html>
<head>
<title>Test</test>
<SCRIPT language="JavaScript" SRC="jxt1.js"></SCRIPT>
</head>
<body>
<A HREF="javascript:a_message()">Click for a message..</A>
</body>
</html> |
When I open the page in IE I don't even see the link. Any suggestions?
*edit- Both files are in the same directory (my desktop) |
________________________________ Freshfemi.net
Too Cool For a Dot Com |
|
|
|
Kdawg
Senior WebHelper
Joined: 21 Apr 2003
Posts: 153
|
Posted:
Mon May 12, 2003 8:34 pm (20 years, 11 months ago) |
|
Here is the correct code
Code: | <html>
<head>
<title>Test</title>
<SCRIPT language="JavaScript" SRC="jxt1.js"></SCRIPT>
</head>
<body>
<A HREF="javascript:a_message()">Click for a message..</A>
</body>
</html> |
Notice <title>Test</test>, thats was the problem. It was just a simple typing mistake. |
|
|
|
|
GXEman
Junior WebHelper
Joined: 07 May 2003
Posts: 27
Location: Athens, GA
|
Posted:
Mon May 12, 2003 8:45 pm (20 years, 11 months ago) |
|
THANKS!
Feel free to bash the HTML newbie anytime. |
________________________________ Freshfemi.net
Too Cool For a Dot Com |
|
|
|
Kdawg
Senior WebHelper
Joined: 21 Apr 2003
Posts: 153
|
Posted:
Mon May 12, 2003 8:50 pm (20 years, 11 months ago) |
|
Ok, you stupid little newbie, maybe you should just quit because you know nothing. LOL just kiding, we were all newbies at one point. Plus it was just a typing mistake. |
|
|
|
|
GXEman
Junior WebHelper
Joined: 07 May 2003
Posts: 27
Location: Athens, GA
|
Posted:
Mon May 12, 2003 9:05 pm (20 years, 11 months ago) |
|
I tried it out on my site and cut my homepage down from ~8 kb to ~3 kb. |
________________________________ Freshfemi.net
Too Cool For a Dot Com |
|
|
|
verto
Senior WebHelper
Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA
|
Posted:
Mon May 12, 2003 9:14 pm (20 years, 11 months ago) |
|
GXEman wrote: | I tried it out on my site and cut my homepage down from ~8 kb to ~3 kb. |
, but don't forget that your .js page still has to load whenever first referenced by your HTML, and unless you're reusing it in another page, may be just adding back the ~4 or ~5K you think you've saved.
GXEman wrote: | THANKS!
Feel free to bash the HTML newbie anytime. |
hey, sounds like fun... (jk)
BTW, one easy way to find that kind of error is to try validating your HTML. While validation can seem pointless and a waste of time (as in 'scr*w the validation, keep coding'), it can very often save time (and hair pulling ) in long run. It's also a cheap and fast way to debug your stuff. |
________________________________ >>>>>>>>>>>>>
GENERAL DISCLAIMER:This disclaimer may be void where null in all cases unless explicitly not unprohibited or (p)re-exclusively assigned by sufficient presedimentation on behalf of every non-interested party to wit (or so it was said).
:::
.: :. . : :....: :.: .: :. verto .: :. . : :....: :.: .: :.
Last edited by verto on Mon May 12, 2003 9:48 pm, edited 3 times in total |
|
|
|
GXEman
Junior WebHelper
Joined: 07 May 2003
Posts: 27
Location: Athens, GA
|
Posted:
Mon May 12, 2003 9:30 pm (20 years, 11 months ago) |
|
I'll keep those tips in mind. Again, thanks for the help guys. |
________________________________ Freshfemi.net
Too Cool For a Dot Com |
|
|
|
|