Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   HTML (http://www.velocityreviews.com/forums/f31-html.html)
-   -   How do you use extenrnal javascript file if script different on each page? (http://www.velocityreviews.com/forums/t164798-how-do-you-use-extenrnal-javascript-file-if-script-different-on-each-page.html)

xyZed 04-12-2006 08:37 AM

How do you use extenrnal javascript file if script different on each page?
 
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

Brian Cryer 04-12-2006 10:21 AM

Re: How do you use extenrnal javascript file if script different on each page?
 
"xyZed" <xyzed@xyzed.co.uk> wrote in message
news:tqep32lg88evb897h1gj3n3jp3k9eomaqg@4ax.com...
>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



Andy Dingley 04-12-2006 10:44 AM

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

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


xyZed 04-12-2006 02:24 PM

Re: How do you use extenrnal javascript file if script different on each page?
 
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

Brian Cryer 04-12-2006 02:41 PM

Re: How do you use extenrnal javascript file if script different on each page?
 
"xyZed" <xyzed@xyzed.co.uk> wrote in message
news:pnup321uaqaks8kg1390085ketldpdf2l4@4ax.com...
> 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



BootNic 04-12-2006 04:40 PM

Re: How do you use extenrnal javascript file if script different on each page?
 
> "xyZed" <xyzed@xyzed.co.uk> wrote:
> news:tqep32lg88evb897h1gj3n3jp3k9eomaqg@4ax.com... .
>
> 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*


xyZed 04-14-2006 10:57 AM

Re: How do you use extenrnal javascript file if script different on each page?
 
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

xyZed 04-14-2006 10:59 AM

Re: How do you use extenrnal javascript file if script different on each page?
 
There is circumstantial evidence that on Wed, 12 Apr 2006 16:40:08
GMT, "BootNic" <Bootnic@bounce.prodigy.net> 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


All times are GMT. The time now is 04:02 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.