JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Javascript in another file Posted by smith99 on 24 Oct 2001 at 9:24 AM
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

Report
Re: Javascript in another file Posted by ArashSayadi on 24 Oct 2001 at 12:57 PM
: 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 <head> tag of every page you wish to use the script in:

<script language="JavaScript" type="text/javascript" src="myScript.js">

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 <script> 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
arashs@pts1.com


Report
Re: Javascript in another file Posted by xapis on 24 Oct 2001 at 1:05 PM
All you do is include the following text at the top of each page:

<!--#include file="includes/functions.js" -->

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:

<!--#include virtual="http://www.a.com/includes/functions.js" -->


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

<script type="text/javascript" language="JavaScript">
<!--
function function1(value_in)
{
do stuff;
}
//-->
</script>


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
:


Report
Re: Javascript in another file Posted by smith99 on 24 Oct 2001 at 1:18 PM
I have added
<script language="JavaScript" type="text/javascript" src="myScript.js"></script>
between the <head></head> 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:
:
: <!--#include file="includes/functions.js" -->
:
: 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:
:
: <!--#include virtual="http://www.a.com/includes/functions.js" -->
:
:
: Your functions.js file would then look something like this:
:
: <script type="text/javascript" language="JavaScript">
: <!--
: function function1(value_in)
: {
: do stuff;
: }
: //-->
: </script>
:
:
: 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
: :
:
:


Report
Re: Javascript in another file Posted by smith99 on 24 Oct 2001 at 1:26 PM
Dont worry, ive done it now. Thanx for your help

: I have added
: <script language="JavaScript" type="text/javascript" src="myScript.js"></script>
: between the <head></head> 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:
: :
: : <!--#include file="includes/functions.js" -->
: :
: : 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:
: :
: : <!--#include virtual="http://www.a.com/includes/functions.js" -->
: :
: :
: : Your functions.js file would then look something like this:
: :
: : <script type="text/javascript" language="JavaScript">
: : <!--
: : function function1(value_in)
: : {
: : do stuff;
: : }
: : //-->
: : </script>
: :
: :
: : 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
: : :
: :
: :
:
:





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.