Global Script

J

JCO

I have a script that is located in every html on my site. Is there anyway
to put this script in a single location and call it from each site. That
way, one change to the script will instantly change every page.

Thanks
 
J

Jon Spivey

Hi,
put your script in a sperate file - without the <script></script> tags so
you might have something like
function doIt(){
//stuff
}
Save this file as script.js. Now you can link to it like this
<script type="text/javascript" src="script.js"></script>
 
S

Steve Easton

Assuming it is a javascript:
Copy it to notepad and save the file
as filename.js.
However in the notepad file leave out the <script></script>
tags

Then in html view
<script type="javascript" src="filename.js>
</script>
 
J

Jim Cheshire

Use the steps you've been given below, but instead of manually adding that
code to each page, use Scripter which you can download free from my Web
site. It will make it easy to apply that script to all pages (or selected
pages) in one easy step.

--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
===================================
Buy my book!
Special Edition Using Microsoft FrontPage 2003
Don't take my word for it. Read the reviews!
===================================
Our newest add-in:
FrontPage Cart Companion
http://www.frontpagecartcompanion.com
 
J

JCO

Thanks all 3-of you. Curious question.
I noticed one had "text/JavaScript..." and the other had just
"JavaScript...".
They both seemed to work, but I was wanting to know why or what's the
difference.
 
J

JCO

Jim
Your addins are great. Thanks so much for the work you've done.
I've added several to my application.
 
J

JCO

What if you want multiple scripts on one page (MyScripts.js). How do you
call the individual scripts with in the script. Or is this a bad idea.
Thanks
 
J

Jim Cheshire

Not a bad idea. Just call it as you normally would.

--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
================================
Author of Special Edition
Using Microsoft Office FrontPage 2003
5 Stars on Amazon and B&N
================================
 
J

JCO

I guess... what I'm getting at is this. Currently my script each begin with

function detect()
{
script goes here!
}

Each script has it's own name, therefore, you call the script by the "name"
(ie MyScript.js).

If I simply repeat (the above block) several times to include each script
section on one *.js, how would you call the specific "code section" (or
function) within the script. You would need to call the script (by name)
then somehow call the individual function that is required, ie
MyScript.func1().

Hope this makes sense.
Is this ever done?
 
S

Stefan B Rusynko

Load the script file in the head section
<script type="text/javascript" src="MyScript.js"></script>
That makes all functions available to the page

Then in the page (or body tag or head section), as needed, call the script Function you need as in:
<body onload="detect();"> or
<a href="GoSomewhere.htm" onclick="detect();">Call a script</a>



| I guess... what I'm getting at is this. Currently my script each begin with
|
| function detect()
| {
| script goes here!
| }
|
| Each script has it's own name, therefore, you call the script by the "name"
| (ie MyScript.js).
|
| If I simply repeat (the above block) several times to include each script
| section on one *.js, how would you call the specific "code section" (or
| function) within the script. You would need to call the script (by name)
| then somehow call the individual function that is required, ie
| MyScript.func1().
|
| Hope this makes sense.
| Is this ever done?
|
| | > Not a bad idea. Just call it as you normally would.
| >
| > --
| > Jim Cheshire
| > Jimco Add-ins
| > http://www.jimcoaddins.com
| > ================================
| > Author of Special Edition
| > Using Microsoft Office FrontPage 2003
| > 5 Stars on Amazon and B&N
| > ================================
| >
| >
| >
| >
| > | > > What if you want multiple scripts on one page (MyScripts.js). How do
| you
| > > call the individual scripts with in the script. Or is this a bad idea.
| > > Thanks
| > >
| > > | > > > Use the steps you've been given below, but instead of manually adding
| > that
| > > > code to each page, use Scripter which you can download free from my
| Web
| > > > site. It will make it easy to apply that script to all pages (or
| > selected
| > > > pages) in one easy step.
| > > >
| > > > --
| > > > Jim Cheshire
| > > > Jimco Add-ins
| > > > http://www.jimcoaddins.com
| > > > ===================================
| > > > Buy my book!
| > > > Special Edition Using Microsoft FrontPage 2003
| > > > Don't take my word for it. Read the reviews!
| > > > ===================================
| > > > Our newest add-in:
| > > > FrontPage Cart Companion
| > > > http://www.frontpagecartcompanion.com
| > > >
| > > >
| > > > | > > > > I have a script that is located in every html on my site. Is there
| > > anyway
| > > > > to put this script in a single location and call it from each site.
| > > That
| > > > > way, one change to the script will instantly change every page.
| > > > >
| > > > > Thanks
| > > > >
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
 
M

MD WebsUnlimited.com

Hi JCO,

Each function definition in the page and in loaded external files is loaded
into the web pages global scope, e.g. each becomes a method of the page. If
two functions contain the same name then the last one loaded overlays the
prior one. That is the functions within a external script file are not
methods of the file.

--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Need to add Meta Tags to your web pages NOW with Google Bot controls.
http://www.websunlimited.com/order/Product/MTM2002/mtm2002_help_dir.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
 
Top