Javascript in another file - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Javascript in another file

smith99smith99 Posts: 21Member
On my website I have a javascript, but this is on everypage and if i want to add something to it i have to update each page. How do I use '.js' or '.class' files within a html document, if this is what im needing.

Thanx

Comments

  • ArashSayadiArashSayadi Posts: 10Member
    : On my website I have a javascript, but this is on everypage and if i want to add something to it i have to update each page. How do I use '.js' or '.class' files within a html document, if this is what im needing.
    :
    : Thanx
    :

    All you need to do is place the script in a source file and call it myScript.js or whatever name you like. Assuming you place this at your root and the pages that you wish to use it in are also at the root, place the following tag between the openning and closing tag of every page you wish to use the script in:



    Of course, you would need to replace myScript.js with whatever name you gave it.

    If your html page is somewhere other than where the script source resides, then you need to put the relative path along with the source file name in the src attribute of the tag, the same way you would refer to an image or a document that resides in a folder other than that of the page you are making the link in.




    Happy Computing,
    Arash Sayadi
    15530-B Rockfield Blvd. Suite 4
    Irvine, CA 92618
    949-830-1623 x36
    949-830-2120 Fax
    www.pts1.com
    [email protected]


  • xapisxapis Posts: 5Member
    All you do is include the following text at the top of each page:



    The "functions.js" file has all the functions you want to use in multiple pages. To include a file outsite of your website root directory use this:




    Your functions.js file would then look something like this:






    Hope this helps
    - Xapis


    : On my website I have a javascript, but this is on everypage and if i want to add something to it i have to update each page. How do I use '.js' or '.class' files within a html document, if this is what im needing.
    :
    : Thanx
    :


  • smith99smith99 Posts: 21Member
    I have added

    between the tags. Now i want the function to be called in the page, how do i do this?
    the function is called 'image()'. sorry but im new to javascripting

    : All you do is include the following text at the top of each page:
    :
    :
    :
    : The "functions.js" file has all the functions you want to use in multiple pages. To include a file outsite of your website root directory use this:
    :
    :
    :
    :
    : Your functions.js file would then look something like this:
    :
    :
    :
    :
    :
    :
    : Hope this helps
    : - Xapis
    :
    :
    : : On my website I have a javascript, but this is on everypage and if i want to add something to it i have to update each page. How do I use '.js' or '.class' files within a html document, if this is what im needing.
    : :
    : : Thanx
    : :
    :
    :


  • smith99smith99 Posts: 21Member
    Dont worry, ive done it now. Thanx for your help

    : I have added
    :
    : between the tags. Now i want the function to be called in the page, how do i do this?
    : the function is called 'image()'. sorry but im new to javascripting
    :
    : : All you do is include the following text at the top of each page:
    : :
    : :
    : :
    : : The "functions.js" file has all the functions you want to use in multiple pages. To include a file outsite of your website root directory use this:
    : :
    : :
    : :
    : :
    : : Your functions.js file would then look something like this:
    : :
    : :
    : :
    : :
    : :
    : :
    : : Hope this helps
    : : - Xapis
    : :
    : :
    : : : On my website I have a javascript, but this is on everypage and if i want to add something to it i have to update each page. How do I use '.js' or '.class' files within a html document, if this is what im needing.
    : : :
    : : : Thanx
    : : :
    : :
    : :
    :
    :


Sign In or Register to comment.