javascript and external javascript files problem

delon

Banned
Messages
397
Reaction score
0
Points
0
i signed up at adbrite.com and got an ad code for my website ( written in javascript ). i dont want to use the javascript code in my source code but use it at as an external .js file. in my source code i entered this javascript in my source code :
<script src="http://www.delon.in/ads/leaderboard.js"></script>

and saved the code in file in leaderboard.js at http://www.delon.in/ads/leaderboard.js. but i cannot view the ads on my website. i saw at w3schools.com that the external javascript file should not have <script></script> tags. i tried editing the code but of no use. it would be great if someone could edit the original ad code so it can run through the external .js file.

original ad code by adbrite ( written in javascript ) :
<!-- Begin: AdBrite -->
<script type="text/javascript">
var AdBrite_Title_Color = '660000';
var AdBrite_Text_Color = '000000';
var AdBrite_Background_Color = 'FFCC66';
var AdBrite_Border_Color = '660000';
var AdBrite_URL_Color = '008000';
</script>
<span style="white-space:nowrap;"><script src="http://ads.adbrite.com/mb/text_group.php?sid=658305&zs=3732385f3930" type="text/javascript"></script><!--
--><a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=658305&afsid=1"><img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-leaderboard-w.gif" style="background-color:#660000;border:none;padding:0;margin:0;" alt="Your Ad Here" width="14" height="90" border="0" /></a></span>
<!-- End: AdBrite -->

please help me, im totally a newbie at programming.:biggrin:
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Okay, the code that you have copied into the .js file is actually html code with a javascript tag that has javascript inside it.

Notice the <script> html tags which are for the javascript and the <a> and <span> html tags which show their actual adds.

The way that this add has been setup by adbrite, you have to copy that code directly into the page that you want to show it in. That will make it work.

Javascript files cannont contain anything but javascript, so that is why putting the html into is was stopping it from working.
 
Last edited:

delon

Banned
Messages
397
Reaction score
0
Points
0
so is there any way in which i can the code in a file and link it to the page so that i when i have to edit the ad code then i wont need to edit all the pages containing that particular code.
 

lszanto

New Member
Messages
23
Reaction score
0
Points
0
If you have php enabled on the site you are trying to do this on you can simple replace the .html at the end and put a .php and then the following will work.

Instead of using <script src="thescript.js" ></script> you can add <?php include "ads.inc"; ?>

And then in the same directory just add this file as ads.inc(it doesn't really matter what extension you give the file, as long as it matches.
Code:
<!-- Begin: AdBrite -->
<script type="text/javascript">
var AdBrite_Title_Color = '660000';
var AdBrite_Text_Color = '000000';
var AdBrite_Background_Color = 'FFCC66';
var AdBrite_Border_Color = '660000';
var AdBrite_URL_Color = '008000';
</script>
<span style="white-space:nowrap;"><script src="http://ads.adbrite.com/mb/text_group.php?sid=658305&zs=3732385f3930" type="text/javascript"></script><!--
--><a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=658305&afsid=1"><img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-leaderboard-w.gif" style="background-color:#660000;border:none;padding:0;margin:0;" alt="Your Ad Here" width="14" height="90" border="0" /></a></span>
<!-- End: AdBrite -->

Or you could just put that html/javascript in the original website, your choice.
Do you understand?
 
Last edited:

delon

Banned
Messages
397
Reaction score
0
Points
0
thanxxxxx, then i also would have to change the extension of my main page to .php ?
 
Last edited:

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Yes, the main page which is going to show the add would have to be a .php page, while the file with the add code in it could be a .html or a .php or a few other types.
 
Top