Storing Scripts on a separate page

Discussion in 'Javascript' started by DeadCert, Feb 5, 2004.

  1. DeadCert

    DeadCert Guest

    Hi, How can I store all my scripts on a separate page and then call
    them from the html page that I want to use them on? the <head> section
    is getting too cluttered and I would like to store all in one place.
    Anyone know how? Cheers
     
    DeadCert, Feb 5, 2004
    #1
    1. Advertising

  2. "DeadCert" <> wrote in message
    news:...
    > Hi, How can I store all my scripts on a separate page and then call
    > them from the html page that I want to use them on? the <head> section
    > is getting too cluttered and I would like to store all in one place.
    > Anyone know how? Cheers


    <script type="text/javascript" src="some.js"></script>

    Where some.js contains JS code only.


    JW
     
    Janwillem Borleffs, Feb 5, 2004
    #2
    1. Advertising

  3. Janwillem Borleffs wrote:

    >>Hi, How can I store all my scripts on a separate page and then call
    >>them from the html page that I want to use them on? the <head> section
    >>is getting too cluttered and I would like to store all in one place.

    >
    > <script type="text/javascript" src="some.js"></script>
    >
    > Where some.js contains JS code only.


    If the OP has several files of javascript already, that doesn't compress
    to one statement, right? I tried this once--I found nothing to include
    javascript from another javascript file, I seem to need a SCRIPT tag for
    every file. Correct me if I'm wrong. I love to be wrong on such issues ;-)

    --
    Bas Cost Budde
    http://www.heuveltop.nl/BasCB
     
    Bas Cost Budde, Feb 5, 2004
    #3
  4. Bas Cost Budde wrote:

    > Janwillem Borleffs wrote:
    >
    >>> Hi, How can I store all my scripts on a separate page and then call
    >>> them from the html page that I want to use them on? the <head> section
    >>> is getting too cluttered and I would like to store all in one place.

    >>
    >>
    >> <script type="text/javascript" src="some.js"></script>
    >>
    >> Where some.js contains JS code only.

    >
    >
    > If the OP has several files of javascript already, that doesn't compress
    > to one statement, right? I tried this once--I found nothing to include
    > javascript from another javascript file, I seem to need a SCRIPT tag for
    > every file. Correct me if I'm wrong. I love to be wrong on such issues ;-)
    >


    You are correct, but there is one solution that comes to mind (I am sure
    there are others)...

    myHtml.html:
    <script type="text/javascript" src="some.js"></script>

    some.js:
    function writeScript( JSfile )
    {
    document.write("<script type='text/javascript' src='" +
    JSfile + "'></scr" + "ipt>");
    }

    writeScript("file1.js");
    writeScript("file2.js");
    writeScript("file3.js");
    ....
     
    Brian Genisio, Feb 5, 2004
    #4
  5. "Bas Cost Budde" <> wrote in message
    news:bvt5n2$6ak$...
    > If the OP has several files of javascript already, that doesn't compress
    > to one statement, right? I tried this once--I found nothing to include
    > javascript from another javascript file, I seem to need a SCRIPT tag for
    > every file. Correct me if I'm wrong. I love to be wrong on such issues ;-)
    >


    You can include one js file, which includes the required files by document
    writing the appropriate script tags.

    Anyways, the OP would benefit from a thorough re-organisation of his
    files...


    JW
     
    Janwillem Borleffs, Feb 5, 2004
    #5
  6. DeadCert

    F. Da Costa Guest

    DeadCert wrote:

    > Hi, How can I store all my scripts on a separate page and then call
    > them from the html page that I want to use them on? the <head> section
    > is getting too cluttered and I would like to store all in one place.
    > Anyone know how? Cheers

    I'm doing exactly the same using frames.
    One of them is reserved for js only.

    It has an additional (could be significant) benefit and that is that you
    can also 'store' interpage states here. So loading a page with knowledge
    about its previous state/ predecessor becomes possible as well.
    Try and do this with a js variable in the page and then reloading it!

    The js frame thus becomes like a library of sorts that is always accessible
    from anywhere within the browser.

    I'm sure there are people that won't like this but it works for me & very
    well so I might add.
    My 2c

    Cheers,
    Fermin DCG
     
    F. Da Costa, Feb 5, 2004
    #6
  7. Brian Genisio wrote:

    > Bas Cost Budde wrote:
    >
    >> If the OP has several files of javascript already, that doesn't
    >> compress to one statement, right? I tried this once--I found nothing
    >> to include javascript from another javascript file, I seem to need a
    >> SCRIPT tag for every file. Correct me if I'm wrong. I love to be wrong
    >> on such issues ;-)

    >
    > You are correct, but there is one solution that comes to mind (I am sure
    > there are others)...
    >
    > myHtml.html:
    > <script type="text/javascript" src="some.js"></script>
    >
    > some.js:
    > function writeScript( JSfile )
    > {
    > document.write("<script type='text/javascript' src='" +
    > JSfile + "'></scr" + "ipt>");
    > }
    >
    > writeScript("file1.js");
    > writeScript("file2.js");
    > writeScript("file3.js");
    > ...
    >

    Now isn't it so that document.write replaces the existing content? That
    is rather harsh for what I have in mind.

    --
    Bas Cost Budde
    http://www.heuveltop.nl/BasCB
     
    Bas Cost Budde, Feb 5, 2004
    #7

  8. >>

    > Now isn't it so that document.write replaces the existing content? That
    > is rather harsh for what I have in mind.
    >


    That is incorrect... in this context. document.write works differently
    in two distinctively different contexts:

    1. While the page is still parsing... Everything written is appended
    after the current script tag, and then parsed into the document

    2. After the page has parsed, ie: an action has occured (such as onLoad,
    onClick, etc)... In this case, it overwrites everything.

    The context I gave, is of type 1. If you do it in inline scripting, you
    have nothing to fear.

    To clarify:

    <SCRIPT ...> document.writeln(...) </SCRIPT>

    will append after the script tag

    <SCRIPT ...> function ABC(...) { document.writeln(...); } </SCRIPT>
    <a href=... onClick="ABC(...)">...</a>

    will wipe out the page with the new text, when the link is clicked

    Brian
     
    Brian Genisio, Feb 5, 2004
    #8
  9. Bas Cost Budde, Feb 5, 2004
    #9
    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. EvgueniB
    Replies:
    1
    Views:
    655
    Anthony Borla
    Dec 15, 2003
  2. tochiromifune

    How to separate content and scripts?

    tochiromifune, Dec 30, 2005, in forum: HTML
    Replies:
    0
    Views:
    424
    tochiromifune
    Dec 30, 2005
  3. Frank Fredstone
    Replies:
    1
    Views:
    460
    Jean-Francois Briere
    Jun 27, 2006
  4. Stefan D
    Replies:
    0
    Views:
    360
    Stefan D
    Apr 14, 2006
  5. JCO
    Replies:
    2
    Views:
    85
Loading...

Share This Page