4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 External Javascripts?
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
GXEman
Junior WebHelper
Junior WebHelper


Joined: 07 May 2003
Posts: 27
Location: Athens, GA

PostPosted: Mon May 12, 2003 5:19 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GXEmanSend Personal Message
verto
Senior WebHelper
Senior WebHelper


Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA

PostPosted: Mon May 12, 2003 5:37 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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>). Wink

________________________________
>>>>>>>>>>>>>
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 .: :. . : :....: :.: .: :.
OfflineView User's ProfileFind all posts by vertoSend Personal Message
GXEman
Junior WebHelper
Junior WebHelper


Joined: 07 May 2003
Posts: 27
Location: Athens, GA

PostPosted: Mon May 12, 2003 7:47 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GXEmanSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Mon May 12, 2003 8:34 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
GXEman
Junior WebHelper
Junior WebHelper


Joined: 07 May 2003
Posts: 27
Location: Athens, GA

PostPosted: Mon May 12, 2003 8:45 pm (20 years, 11 months ago) Reply with QuoteBack to Top

THANKS!
Feel free to bash the HTML newbie anytime.

________________________________
Freshfemi.net
Too Cool For a Dot Com
OfflineView User's ProfileFind all posts by GXEmanSend Personal Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Mon May 12, 2003 8:50 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
GXEman
Junior WebHelper
Junior WebHelper


Joined: 07 May 2003
Posts: 27
Location: Athens, GA

PostPosted: Mon May 12, 2003 9:05 pm (20 years, 11 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by GXEmanSend Personal Message
verto
Senior WebHelper
Senior WebHelper


Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA

PostPosted: Mon May 12, 2003 9:14 pm (20 years, 11 months ago) Reply with QuoteBack to Top

GXEman wrote:
I tried it out on my site and cut my homepage down from ~8 kb to ~3 kb.

Cool, 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. Surprised

GXEman wrote:
THANKS!
Feel free to bash the HTML newbie anytime.


hey, sounds like fun... Wink (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 Laughing ) in long run. It's also a cheap and fast way to debug your stuff. Wink

________________________________
>>>>>>>>>>>>>
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
OfflineView User's ProfileFind all posts by vertoSend Personal Message
GXEman
Junior WebHelper
Junior WebHelper


Joined: 07 May 2003
Posts: 27
Location: Athens, GA

PostPosted: Mon May 12, 2003 9:30 pm (20 years, 11 months ago) Reply with QuoteBack to Top

I'll keep those tips in mind. Again, thanks for the help guys.

________________________________
Freshfemi.net
Too Cool For a Dot Com
OfflineView User's ProfileFind all posts by GXEmanSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.203864 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme