How do you use extenrnal javascript file if script different on each page?

X

xyZed

I want to use external javascript files. The only javascript I have is
from affiliate links and many pages have different ads with different
scripts. Is there anyway I can still use an external file? Or would I
have to use several different ones? If so would this cause any
problems?

Would you be able to reference particular parts of javascript in a
file containing dozens of affiliate scripts?



--

Free washing machine help and advice.

www.washerhelp.co.uk

www.xyzed.co.uk/newsgroups/top-posting.html
 
B

Brian Cryer

xyZed said:
I want to use external javascript files. The only javascript I have is
from affiliate links and many pages have different ads with different
scripts. Is there anyway I can still use an external file? Or would I
have to use several different ones? If so would this cause any
problems?

Would you be able to reference particular parts of javascript in a
file containing dozens of affiliate scripts?

I think there are many different ways forward. A simple approach would be to
have a different JavaScript file for each ad. Assuming that the JavaScript
file contained statements like "document.write(...." to actually generate
any necessary html (because ads are normally a combination of html and
JavaScript) then you could place the reference to the external JavaScript
file in your html at the points where you wanted the ad to appear.

Do you have any form of server side scripting available to you? If you did
then looking at that might provide you with greater flexibilility.

Hope this helps.
 
A

Andy Dingley

xyZed said:
I want to use external javascript files. The only javascript I have is
from affiliate links and many pages have different ads with different
scripts. Is there anyway I can still use an external file?

Yes. You might not be able to put _all_ of your JS into it though.

Stick the complicated stuff into an external .js file,
write simple wrapper functions that pass page-specific parameters into
a common core function, and store these wrapper functions on the page.

This doesn't "strip all the JS out of the page", but it does remove
nearly all of the complex JS you might have to maintain later into one
central copy, and that's what really matters.

You can also re-write your JS to be less dependent on parameters and
more dependent on context when it's called. This is mainly a technique
for lists of thumbnail images and similar situations - rather than
hard-coding each call with a string constant for the image URL, have it
read the necessary information from the HTML element that raised the
event. (This can be tricky to do well cross-platform though).
 
X

xyZed

There is circumstantial evidence that on Wed, 12 Apr 2006 11:21:44
› Do you have any form of server side scripting available to you? If you did
› then looking at that might provide you with greater flexibilility.

This is an example of the average affiliate javascript I use (which
I've disabled by changing numbers)

<script type="text/javascript"><!--//
var uri = 'http://impgb.tradedoubler.com/imp/img/**369/***9419?' + new
String (Math.random()).substring (2, 11);
document.write('<a
href="http://clkuk.tradedoubler.com/click?p=12**&amp;a=10***19&amp;g=5**69"><img
src="'+uri+'"><\/a>');
//--></script>


On pages containing these ads, I try not to use more than 2 or 3 on
any page so I'm wondering if it's worth the effort of trying to put
them in a seperate file to be honest.

--

Free washing machine help and advice.

www.washerhelp.co.uk

www.xyzed.co.uk/newsgroups/top-posting.html
 
B

Brian Cryer

xyZed said:
There is circumstantial evidence that on Wed, 12 Apr 2006 11:21:44


This is an example of the average affiliate javascript I use (which
I've disabled by changing numbers)

<script type="text/javascript"><!--//
var uri = 'http://impgb.tradedoubler.com/imp/img/**369/***9419?' + new
String (Math.random()).substring (2, 11);
document.write('<a
href="http://clkuk.tradedoubler.com/click?p=12**&amp;a=10***19&amp;g=5**69"><img
src="'+uri+'"><\/a>');
//--></script>


On pages containing these ads, I try not to use more than 2 or 3 on
any page so I'm wondering if it's worth the effort of trying to put
them in a seperate file to be honest.

Whether its worth putting them in separate files is your call, but I think I
would. Okay, its more agro to get it all set up in the first place, but if
at a later time you decide that you want to replace one advert with another
then its simply a case of editing the external JavaScript file and all the
html pages that reference it won't need to be touched. It all depends on how
may files you have on your site.

I know you didn't ask, but: In my experience if you get the right ads (and
that's an art I've not yet mastered), the right ad will easily out perform
Google Adsense. However, if you are not sure which ads would be good on a
page then make use of Google Adsense. I have 4 or 5 pages on my site which
bring in any real advertising revenue via CJ and others, Google Adsense
brings in about twice as much as those combined across the rest of my site.
Just a thought.

By the way, I like the look of your www.washerhelp.co.uk site. It looks like
a genuinely useful site (and I think you have a good point about
top-posting).
 
B

BootNic

xyZed said:
I want to use external javascript files. The only javascript I have
is from affiliate links and many pages have different ads with
different scripts. Is there anyway I can still use an external
file? Or would I have to use several different ones? If so would
this cause any problems?

Would you be able to reference particular parts of javascript in a
file containing dozens of affiliate scripts?

<script type="text/javascript">
page = window.location.href.match(/[^\/]*$/);
switch (true) {
case(page=='index.htm') :
document.write('This could be the index page.');
break;
case(page=='search.htm') :
document.write('What ya lookin for?')
break;
default:
document.write('I don\'t know where you are or how you got here!')
}
</script>

--
BootNic Wednesday, April 12, 2006 12:40 PM

People grow through experience if they meet life honestly and
courageously. This is how character is built.
*Eleanor Roosevelt*
 
X

xyZed

There is circumstantial evidence that on Wed, 12 Apr 2006 16:40:08
› <script type="text/javascript">
› page = window.location.href.match(/[^\/]*$/);
› switch (true) {
› case(page=='index.htm') :
› document.write('This could be the index page.');
› break;
› case(page=='search.htm') :
› document.write('What ya lookin for?')
› break;
› default:
› document.write('I don\'t know where you are or how you got here!')
› }
› </script>

Thanks (and thanks Andy too) I at least know it's possible now, even
though I don't really understand the javascript :)

--

Free washing machine help and advice.

www.washerhelp.co.uk

www.xyzed.co.uk/newsgroups/top-posting.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top