Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > How do you use extenrnal javascript file if script different on each page?

Reply
Thread Tools

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

 
 
xyZed
Guest
Posts: n/a
 
      04-12-2006
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
 
Reply With Quote
 
 
 
 
Brian Cryer
Guest
Posts: n/a
 
      04-12-2006
"xyZed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
--
Brian Cryer
www.cryer.co.uk/brian


 
Reply With Quote
 
 
 
 
Andy Dingley
Guest
Posts: n/a
 
      04-12-2006

xyZed wrote:
> 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).

 
Reply With Quote
 
xyZed
Guest
Posts: n/a
 
      04-12-2006
There is circumstantial evidence that on Wed, 12 Apr 2006 11:21:44
+0100, "Brian Cryer" <brianc@127.0.0.1.activesol.co.uk> wrote
__________________________________________________ _____

> 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
 
Reply With Quote
 
Brian Cryer
Guest
Posts: n/a
 
      04-12-2006
"xyZed" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> There is circumstantial evidence that on Wed, 12 Apr 2006 11:21:44
> +0100, "Brian Cryer" <brianc@127.0.0.1.activesol.co.uk> wrote
> __________________________________________________ _____
>
>>> 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.


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).
--
Brian Cryer
www.cryer.co.uk


 
Reply With Quote
 
BootNic
Guest
Posts: n/a
 
      04-12-2006
> "xyZed" <(E-Mail Removed)> wrote:
> news:(E-Mail Removed)... .
>
> 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*

 
Reply With Quote
 
xyZed
Guest
Posts: n/a
 
      04-14-2006
There is circumstantial evidence that on Wed, 12 Apr 2006 15:41:04
+0100, "Brian Cryer" <brianc@127.0.0.1.activesol.co.uk> wrote
__________________________________________________ _____


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


Thanks. I've got some good links from yours too.

--

Free washing machine help and advice.

www.washerhelp.co.uk

www.xyzed.co.uk/newsgroups/top-posting.html
 
Reply With Quote
 
xyZed
Guest
Posts: n/a
 
      04-14-2006
There is circumstantial evidence that on Wed, 12 Apr 2006 16:40:08
GMT, "BootNic" <(E-Mail Removed)> wrote
__________________________________________________ _____

> <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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform a 2D color image into 2 images of (R1,G1,B) at each pixelof image 1 and (R2,G2,B) at each pixel of image2 for STEREO visualization 88888 Dihedral C++ 10 12-23-2011 02:28 PM
Hash .each and different action for each key Igor Nn Ruby 7 05-28-2011 12:33 PM
Array#each - getting each element and the index Pat Maddox Ruby 6 01-20-2006 04:04 PM
how do i? Full scan of each control in each grid row cell John Blair ASP .Net 1 08-03-2005 11:02 AM
xsl:for-each for each 3 elements problem Tjerk Wolterink XML 3 11-03-2004 05:22 PM



Advertisments