Storing Scripts on a separate page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DeadCert

    #1

    Storing Scripts on a separate page

    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
  • Janwillem Borleffs

    #2
    Re: Storing Scripts on a separate page


    "DeadCert" <rekdagaf@hotma il.com> wrote in message
    news:b5e71cee.0 402042134.30fac c61@posting.goo gle.com...[color=blue]
    > 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[/color]

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

    Where some.js contains JS code only.


    JW



    Comment

    • Bas Cost Budde

      #3
      Re: Storing Scripts on a separate page

      Janwillem Borleffs wrote:
      [color=blue][color=green]
      >>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.[/color]
      >
      > <script type="text/javascript" src="some.js"></script>
      >
      > Where some.js contains JS code only.[/color]

      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


      Comment

      • Janwillem Borleffs

        #4
        Re: Storing Scripts on a separate page


        "Bas Cost Budde" <bas@heuveltop. org> wrote in message
        news:bvt5n2$6ak $9@news2.solcon .nl...[color=blue]
        > 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 ;-)
        >[/color]

        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




        Comment

        • Brian Genisio

          #5
          Re: Storing Scripts on a separate page

          Bas Cost Budde wrote:
          [color=blue]
          > Janwillem Borleffs wrote:
          >[color=green][color=darkred]
          >>> 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.[/color]
          >>
          >>
          >> <script type="text/javascript" src="some.js"></script>
          >>
          >> Where some.js contains JS code only.[/color]
          >
          >
          > 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 ;-)
          >[/color]

          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("fi le1.js");
          writeScript("fi le2.js");
          writeScript("fi le3.js");
          ....

          Comment

          • F. Da Costa

            #6
            Re: Storing Scripts on a separate page

            DeadCert wrote:
            [color=blue]
            > 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[/color]
            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

            Comment

            • Bas Cost Budde

              #7
              Re: Storing Scripts on a separate page

              Brian Genisio wrote:
              [color=blue]
              > Bas Cost Budde wrote:
              >[color=green]
              >> 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 ;-)[/color]
              >
              > 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("fi le1.js");
              > writeScript("fi le2.js");
              > writeScript("fi le3.js");
              > ...
              >[/color]
              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


              Comment

              • Brian Genisio

                #8
                Re: Storing Scripts on a separate page

                [color=blue][color=green]
                >>[/color]
                > Now isn't it so that document.write replaces the existing content? That
                > is rather harsh for what I have in mind.
                >[/color]

                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.writel n(...) </SCRIPT>

                will append after the script tag

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

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

                Brian

                Comment

                • Bas Cost Budde

                  #9
                  Re: Storing Scripts on a separate page

                  Thank you.
                  --
                  Bas Cost Budde


                  Comment

                  Working...