homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Help Please :::: External .JS File
NeedScripts




msg:1471674
 4:26 am on Oct 22, 2002 (gmt 0)

I am wanting to use external.js file for banner code, however, I am not able to make it work.

1) There are tons of category on the site (site on profile).
2) I would like to make a sub dir under root, called /jsfiles/
3) I have heard at WebmasterWorld that absolute link cannot be used but I found couple sites, that says something different [ (a) [javascript-fx.com...] & (b) [html4me.com...] ]

I was wondering, if you I can get some suggestion, on how I can use absolute path to external.js for below code


<script language='JavaScript' type='text/javascript'>
<!--
if (!document.phpAds_used) document.phpAds_used = ',';
document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://ads.needscripts.com/adjs.php?n=aa2d578c");
document.write ("&amp;what=zone:29");
document.write ("&amp;exclude=" + document.phpAds_used);
document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://ads.needscripts.com/adclick.php?n=aa2d578c'><img src='http://ads.needscripts.com/adview.php?what=zone:29&amp;n=aa2d578c' border='0' alt=''></a></noscript>

Thanks for the help.

 

maccas




msg:1471675
 4:50 am on Oct 22, 2002 (gmt 0)

Wow twice in one day :)

Put <script src="/jsfiles/ads.js">
</script> in head and put everything between <script language='JavaScript' type='text/javascript'> and </script> (not those tags) in /jsfiles/ads.js

NeedScripts




msg:1471676
 5:12 am on Oct 22, 2002 (gmt 0)

Put <script src="/jsfiles/ads.js"> </script> in head

Sorry for another stupid question.

Suppose I put <script src="http://www.domain.com/jsfiles/ads.js"> </script> in head, but how will the banner show up on the differnt part of page?

And when you say put everything in /jsfiles/ads.js file, with everything you mean


<script language='JavaScript' type='text/javascript'>
<!--
if (!document.phpAds_used) document.phpAds_used = ',';
document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://ads.needscripts.com/adjs.php?n=aa2d578c");
document.write ("&amp;what=zone:29");
document.write ("&amp;exclude=" + document.phpAds_used);
document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://ads.needscripts.com/adclick.php?n=aa2d578c'><img src='http://ads.needscripts.com/adview.php?what=zone:29&amp;n=aa2d578c' border='0' alt=''></a></noscript>

right?

maccas




msg:1471677
 5:25 am on Oct 22, 2002 (gmt 0)

Oh sorry not in the head, where ever you want your banner to appear. Yeah you can use <script src="http://www.domain.com/jsfiles/ads.js"> </script> I would use /jsfiles/ads.js just in case in the future you decide to change domain names, it dosn't matter if you have a page at /a/b/c/d/ or /a/ the slash at the start means relative to root. No do not put <script language='JavaScript' type='text/javascript'> and</script> in your external file, that is most likely why you are getting a error. I am not sure about the noscript tag maybe you could use SSI to add the code.

NeedScripts




msg:1471678
 5:42 am on Oct 22, 2002 (gmt 0)

I am not sure about the noscript tag maybe you could use SSI to add the code.

Hey, that was the problem, I tried tons of tricks but nothing worked, however, lastly after reading your post, I tried removing the noscript tag and *boom*, it worked.

Now another problem. Is there a way, I can also include the SSI tag or noscript in the ads.js file? cuz, it would be super boring to create two files (one ssi and other .js) for every banner.

NeedScripts




msg:1471679
 6:08 am on Oct 22, 2002 (gmt 0)

By the way, one more question.

I have heard that using JavaScript on the website increases the load time, now if I were to use .js file, would the load time be changed any? (hopefully reduced?)

Reflect




msg:1471680
 11:49 am on Oct 22, 2002 (gmt 0)

I have heard that using JavaScript on the website increases the load time, now if I were to use .js file, would the load time be changed any?

I don't think external JS is cached, I could be wrong. However a plus is the spiders will bypass the external JS and this will in turn push your content closer up to the <body> tag.

Brian

g1smd




msg:1471681
 11:49 pm on Oct 23, 2002 (gmt 0)


If you are using the same external .js file on several HTML pages, then page loading will be faster as the .js file is cached in the browser.

Don't forget to include the type="text/javascript" and the language="javascript" attributes within the script tag.

Note that script tags can go within the head or body, but noscript tags must only go in the body section of an HTML document.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved