faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

67 of 97 people (69%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

JavaScript: File: Include: SCRIPT: How to use SRC to load common JavaScript file into my HTML file?

Apr 7th, 2008 23:31
ha mo, Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 22 September 2003 - 04:58 pm ------------------
JavaScript: File: Include: SCRIPT: How to use SRC to load common 
JavaScript file into my HTML file?
---
Use the HTML keyword 'SCRIPT', with the attribute 'SRC'
---
---
Specific example
(e.g. a common header logo in all your HTML files of your website)
Steps: Overview:
 1. -To load the JavaScript common source file (e.g. with header
     information), put this in your HTML files
     1. Put this in your main HTML file located in the
        root directory of your website (that will
        load that JavaScript source file into that
        main HTML page):
        <SCRIPT
          LANGUAGE="JavaScript"
          SRC="yourjavascriptsourcefilename1.js"
        >
        </SCRIPT>
     2. Put this any of your subdirectory HTML file (in the special
        case that you have decided to keep all your Javascript source
        files in the root directory):
        <SCRIPT
          LANGUAGE="JavaScript"
          SRC="..\yourjavascriptsourcefilename1.js"
        >
        </SCRIPT>
 2. -To call the necessary JavaScript procedures or functions:
     1. Put this in your main HTML file
     (assumed is that the common picture is located (only once present,
      and nowhere else) in the root directory:
      <SCRIPT
        LANGUAGE="JavaScript"
      >
       PROCPageHeaderCommon( "" );
      </SCRIPT>
     2. Put this in your subdirectory HTML file
     (assumed is that the common picture is located (only once present,
      and nowhere else) in the root directory, so to get it, you
      go one level up (so using '..\\').
      Note: The double '\\' is necessary to escape the '\' character in
      JavaScript.
      <SCRIPT
        LANGUAGE="JavaScript"
      >
       PROCPageHeaderCommon( "..\\" );
      </SCRIPT>
  3. Put this in this common JavaScript source file, and store it in
     your root directory of your website:
      Just an example to load a central logo by all HTML pages in e.g.
      the subdirectories:
      // if parameter s = "", then you call the central logo located in
      // the root directory.
      // if parameter s = "..\\", then you call from a subdirectory the
      // same central logo located in the root directory
      // library: HTML: Page: Header: Common 
      function PROCPageHeaderCommon( s ) {
        document.write( "<IMG" );
        document.write( '  ALT=""' );
        document.write( '  BORDER="0"' );
        document.write( '  HEIGHT="300"' );
        document.write( '  SRC="' + s + 'mylogo.jpg"' );
        document.write( '  style=width:' + 0.950 * screen.width 
+ "px" ); // same relative width in all screen resolutions 
        document.write( ">" );
      }
---
---
In general:
Steps: Overview:
 1. -Put this in your HTML file
     1. Put this in your main HTML file, to load all your possible
        JavaScript source files:
        <SCRIPT
          LANGUAGE="JavaScript"
          SRC="yourjavascriptsourcefilename1.js"
        >
        </SCRIPT>
       <SCRIPT
          LANGUAGE="JavaScript"
          SRC="yourjavascriptsourcefilename2.js"
        >
        </SCRIPT>
        ...
       <SCRIPT
          LANGUAGE="JavaScript"
          SRC="yourjavascriptsourcefilenamelast.js"
        >
        </SCRIPT>
     2. Put this any of your subdirectory HTML file
        (in the special case that you keep all your
         Javascript source files in the root directory)
        <SCRIPT
          LANGUAGE="JavaScript"
          SRC="..\yourjavascriptsourcefilename.js"
        >
        </SCRIPT>
       <SCRIPT
          LANGUAGE="JavaScript"
          SRC="..\yourjavascriptsourcefilename2.js"
        >
        </SCRIPT>
        ...
       <SCRIPT
          LANGUAGE="JavaScript"
          SRC="..\yourjavascriptsourcefilenamelast.js"
        >
        </SCRIPT>
  2. Put this in your main or subdirectory HTML file, to call all your
     possible functions located in this JavaScript source files
     (for example put it just after the '<BODY>' tag in that HTML
      file):
        <SCRIPT
          LANGUAGE="JavaScript"
        >
          PROCMyProcedure1( myparameter11, myparameter12, ..., 
myparameterlast1 );
        </SCRIPT>
        <SCRIPT
          LANGUAGE="JavaScript"
        >
          PROCMyProcedure2( myparameter21, myparameter22, ..., 
myparameterlast2 );
        </SCRIPT>
        ...
        <SCRIPT
          LANGUAGE="JavaScript"
        >
          PROCMyProcedureLast( myparameter21, myparameter22, ..., 
myparameterlastlast );
        </SCRIPT>
 3. -Put this in your JavaScript source files:
      Note: in your JavaScript file, do NOT put in <SCRIPT> ...
            </SCRIPT>, as this are HTML tags, and not JavaScript tags,
            but use or 'document.write', or use a JavaScript function.
            So pure JavaScript, and not HTML tags in general.
      function PROCMyProcedure1( myparameter11, myparameter12, ..., 
myparameterlast1 ) {
      // do something
      }
      function PROCMyProcedure2( myparameter11, myparameter12, ..., 
myparameterlast1 ) {
      // do something
      }
      function PROCMyProcedureLast( myparameter21, myparameter22, ..., 
myparameterlastlast ) {
      // do something
      }
---
---
Internet: see also:
---
Specific example and some more ideas:
http://groups.google.com/groups?
q=javascript+src+include+header+HTML&hl=en&lr=&ie=UTF-
8&selm=39AA96E1.B09B070B%40ems.jsc.nasa.gov&rnum=6
---
Specific example and some more ideas:
http://groups.google.com/groups?
q=javascript+src+include+header+HTML&hl=en&lr=&ie=UTF-
8&selm=FBqF2.4200%243G5.3067%40news.rdc2.occa.home.com&rnum=5
---
How can I include a number of .js files?
http://www.faqts.com/knowledge_base/view.phtml/aid/11484/fid/126
---
How can I get 2 scripts to work on the same page in both NN and IE, I 
tried including the unload for both in the body but it only works in 
IE.
http://www.faqts.com/knowledge_base/view.phtml/aid/4767/fid/53
---
What are the attributes for the HTML <SCRIPT> tag?
http://www.devguru.com/Technologies/html/quickref/html_script.html
----------------------------------------------------------------------
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com