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

Discussion in 'HTML' started by xyZed, Apr 12, 2006.

  1. xyZed

    xyZed Guest

    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
     
    xyZed, Apr 12, 2006
    #1
    1. Advertising

  2. xyZed

    Brian Cryer Guest

    "xyZed" <> wrote in message
    news:...
    >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
     
    Brian Cryer, Apr 12, 2006
    #2
    1. Advertising

  3. xyZed

    Andy Dingley Guest

    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).
     
    Andy Dingley, Apr 12, 2006
    #3
  4. xyZed

    xyZed Guest

    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
     
    xyZed, Apr 12, 2006
    #4
  5. xyZed

    Brian Cryer Guest

    "xyZed" <> wrote in message
    news:p...
    > 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
     
    Brian Cryer, Apr 12, 2006
    #5
  6. xyZed

    BootNic Guest

    > "xyZed" <> wrote:
    > news:....
    >
    > 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*
     
    BootNic, Apr 12, 2006
    #6
  7. xyZed

    xyZed Guest

    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, Apr 14, 2006
    #7
  8. xyZed

    xyZed Guest

    There is circumstantial evidence that on Wed, 12 Apr 2006 16:40:08
    GMT, "BootNic" <> 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
     
    xyZed, Apr 14, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Louden
    Replies:
    2
    Views:
    320
    Scott M.
    Nov 1, 2003
  2. Richard
    Replies:
    0
    Views:
    347
    Richard
    Sep 1, 2004
  3. =?Utf-8?B?U0I=?=

    Different login page for each document...

    =?Utf-8?B?U0I=?=, Jan 19, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    426
    David Jessee
    Jan 20, 2005
  4. Igor Nn
    Replies:
    7
    Views:
    437
    Johnny Morrice
    May 28, 2011
  5. Healthy Stealthy

    Load a different Flash file each time page loads

    Healthy Stealthy, Oct 29, 2006, in forum: Javascript
    Replies:
    1
    Views:
    143
Loading...

Share This Page