How to create JS includes

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

    How to create JS includes

    Hello,

    This should be a simple question to anyone who knows JavaScript, but I'm new
    to it.

    I have a JavaScript that I need to use in many pages. How do I create JS
    includes?

    I tried the standard method - created a text file, then includud it like
    this:

    <!-------------#Include File="includes/js.txt"------------------->

    but this did't work for me.

    I would appreciate your advice.

    Thank you,

    --
    Peter Afonin


  • Cycloneous Echevarria

    #2
    Re: How to create JS includes

    Peter this is how:

    <html>
    <head>
    <title>Test!</title>
    <!-- now include script tag with src attribute pointing to -->
    <!-- to your script -->
    <script language="javas cript" type="text/javascript" src="test.js">
    <!-- //

    // -->
    </script>
    </head>
    <body>
    Hello World!
    </body>
    </html>

    Peter Afonin wrote:
    [color=blue]
    > Hello,
    >
    > This should be a simple question to anyone who knows JavaScript, but I'm new
    > to it.
    >
    > I have a JavaScript that I need to use in many pages. How do I create JS
    > includes?
    >
    > I tried the standard method - created a text file, then includud it like
    > this:
    >
    > <!-------------#Include File="includes/js.txt"------------------->
    >
    > but this did't work for me.
    >
    > I would appreciate your advice.
    >
    > Thank you,
    >[/color]

    Comment

    • Peter Afonin

      #3
      Re: How to create JS includes

      Thank you!

      I assume that test.js is just a text file that I assign a "js" extension,
      correct?

      Peter

      "Cycloneous Echevarria" <orlando@engr.u conn.edu> wrote in message
      news:409BBBC3.8 020807@engr.uco nn.edu...[color=blue]
      > Peter this is how:
      >
      > <html>
      > <head>
      > <title>Test!</title>
      > <!-- now include script tag with src attribute pointing to -->
      > <!-- to your script -->
      > <script language="javas cript" type="text/javascript" src="test.js">
      > <!-- //
      >
      > // -->
      > </script>
      > </head>
      > <body>
      > Hello World!
      > </body>
      > </html>
      >
      > Peter Afonin wrote:
      >[color=green]
      > > Hello,
      > >
      > > This should be a simple question to anyone who knows JavaScript, but I'm[/color][/color]
      new[color=blue][color=green]
      > > to it.
      > >
      > > I have a JavaScript that I need to use in many pages. How do I create JS
      > > includes?
      > >
      > > I tried the standard method - created a text file, then includud it like
      > > this:
      > >
      > > <!-------------#Include File="includes/js.txt"------------------->
      > >
      > > but this did't work for me.
      > >
      > > I would appreciate your advice.
      > >
      > > Thank you,
      > >[/color][/color]


      Comment

      • Murray

        #4
        Re: How to create JS includes


        "Peter Afonin" <pafo@specialty pulltabs.com> wrote in message
        news:109nicvc1g 1r393@corp.supe rnews.com...[color=blue]
        > Thank you!
        >
        > I assume that test.js is just a text file that I assign a "js" extension,
        > correct?[/color]

        That is correct.


        Comment

        • Peter Afonin

          #5
          Re: How to create JS includes

          Thank you!

          Peter

          "Murray" <parps@SPAMoffS PAMMER.optusSP4 Mnet.com.au> wrote in message
          news:409bcc3b$0 $25007$afc38c87 @news.optusnet. com.au...[color=blue]
          >
          > "Peter Afonin" <pafo@specialty pulltabs.com> wrote in message
          > news:109nicvc1g 1r393@corp.supe rnews.com...[color=green]
          > > Thank you!
          > >
          > > I assume that test.js is just a text file that I assign a "js"[/color][/color]
          extension,[color=blue][color=green]
          > > correct?[/color]
          >
          > That is correct.
          >
          >[/color]


          Comment

          • Ivo

            #6
            Re: How to create JS includes

            > Peter Afonin wrote:[color=blue][color=green]
            > > I have a JavaScript that I need to use in many pages. How do I create JS
            > > includes?[/color][/color]

            "Cycloneous Echevarria" topposted[color=blue]
            > Peter this is how:
            >
            > <html>
            > <head>
            > <title>Test!</title>
            > <!-- now include script tag with src attribute pointing to -->
            > <!-- to your script -->
            > <script language="javas cript" type="text/javascript" src="test.js">
            > <!-- //
            >
            > // -->
            > </script>
            > </head>
            > <body>
            > Hello World!
            > </body>
            > </html>[/color]

            A nice bare-bones example. Two remarks on the side: The script element has
            no language attribute. It may have had one in the past, but that is history.
            To reduce unnecessary webtraffic and in order to "validate", you should
            remove the portion which reads <... language="javas cript" ...> from the
            script tag. Also, the custom of hiding script from older browsers by
            encapsulating the script's content in <!-- --> SGML comments is obsolete.
            These "older browsers" that do not know about the script tag, are history
            too.

            You can also make the src point to a script on another website. Socalled
            hit-counters often do this. Simply by entering the whole address, including
            http protocol. Just be aware that cross-domain security restrictions apply.

            As a last remark, a script element that has a src defined, will ignore any
            content inside the tag itself. Only if the source file is not found or there
            some other error loading the external script, will the engine consider and
            execute any script hardcoded inside the tag.

            HTH
            Ivo


            Comment

            • Dr John Stockton

              #7
              Re: How to create JS includes

              JRS: In article <109ndofba7luk5 4@corp.supernew s.com>, seen in
              news:comp.lang. javascript, Peter Afonin <pafo@specialty pulltabs.com>
              posted at Fri, 7 May 2004 09:17:37 :
              [color=blue]
              >I have a JavaScript that I need to use in many pages. How do I create JS
              >includes?
              >
              >I tried the standard method - created a text file, then includud it like
              >this:
              >
              ><!-------------#Include File="includes/js.txt"------------------->
              >
              >but this did't work for me.[/color]

              Bearing in mind where much system software is written, you should not
              expect just one standard for anything.

              See <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm>.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              • Dr John Stockton

                #8
                Re: How to create JS includes

                JRS: In article <409beeb0$0$541 39$1b2cd167@new s.wanadoo.nl>, seen in
                news:comp.lang. javascript, Ivo <no@thank.you > posted at Fri, 7 May 2004
                22:16:57 :
                [color=blue]
                > Also, the custom of hiding script from older browsers by
                >encapsulatin g the script's content in <!-- --> SGML comments is obsolete.
                >These "older browsers" that do not know about the script tag, are history
                >too.[/color]

                You are here making the assumption that the script will be read only by
                browsers; that is no more than an assumption.

                The master copies of my own web pages are most frequently read by a
                tool, CHEKLINX, which is affected by seeing these comment delimiters;
                without them, the normally-satisfactory javascript if (b<a) needs
                to be re-written as if (b< a) or if (b < a ) .

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                Working...