Defer the call of an external .js file

Discussion in 'Javascript' started by Jim Adamson, Dec 15, 2004.

  1. Jim Adamson

    Jim Adamson Guest

    Hi

    I want to defer the call of an external .js file so that when the link
    in the page is clicked, the .js file is downloaded and
    included in the page. The link would also pass on some arguments to
    the function in the page. Once the .js file is successfully
    downloaded/included, I would then like to pass on the arguments from
    this function to the function
    that is within the .js file and call the function that's inside the
    ..js file from the function in the page. Is this possible ? Here's the
    sort of thing that I've tried but I get "Is not defined errors"
    presumably because the function in the .js file hasn't been
    incorporated into the page after clicking the link.


    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function dload(id,name,street)
    document.write('<script src="whatever.js"><\/script>');
    jsfunction(id,name,street)
    </SCRIPT>
    </head>
    <body>
    <a href="javascript:dload('12345','john','Westwood St');">Link</a>
    </body>
    </html>

    thanks
    Jim
     
    Jim Adamson, Dec 15, 2004
    #1
    1. Advertising

  2. Jim Adamson

    Evertjan. Guest

    Jim Adamson wrote on 15 dec 2004 in comp.lang.javascript:

    > I want to defer the call of an external .js file so that when the link
    > in the page is clicked, the .js file is downloaded and
    > included in the page.


    Make two similar pages, one with, one without the .js

    However such belated loading is never necessary,
    as immediate loading and clever programming suffice.

    I suppose you are ready for some serverside programming.

    ;-}

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 15, 2004
    #2
    1. Advertising

  3. Jim Adamson

    RobB Guest

    Jim Adamson wrote:

    >
    > I want to defer the call of an external .js file so that when the

    link
    > in the page is clicked, the .js file is downloaded and
    > included in the page.
    >


    The appropriate word here is 'load' - you don't call files.

    Just use an ordinary link. All browsers afaik will dump imported files
    with mimetype 'application/x-javascript' right into the JavaScript
    execution environment without disturbing the loaded page, regardless of
    file extension, allowing dynamically assembled files - '.php', '.asp',
    '.jsp' e.g. - to be accessed as well.
     
    RobB, Dec 15, 2004
    #3
    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. wladimir

    Defer problem

    wladimir, Jan 7, 2009, in forum: Python
    Replies:
    0
    Views:
    266
    wladimir
    Jan 7, 2009
  2. Artūras Šlajus
    Replies:
    7
    Views:
    327
    Pete Brumm
    Apr 16, 2010
  3. Ken Ghosh

    EventMachine::Defer + Weird issue

    Ken Ghosh, Oct 22, 2010, in forum: Ruby
    Replies:
    0
    Views:
    138
    Ken Ghosh
    Oct 22, 2010
  4. William F.

    EventMachine & EM.defer

    William F., Jan 19, 2011, in forum: Ruby
    Replies:
    1
    Views:
    635
    Bryan Richardson
    Jan 19, 2011
  5. pantagruel
    Replies:
    3
    Views:
    99
    Fred Oz
    Mar 21, 2005
Loading...

Share This Page