Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Storing Scripts on a separate page

Reply
Thread Tools

Storing Scripts on a separate page

 
 
DeadCert
Guest
Posts: n/a
 
      02-05-2004
Hi, How can I store all my scripts on a separate page and then call
them from the html page that I want to use them on? the <head> section
is getting too cluttered and I would like to store all in one place.
Anyone know how? Cheers
 
Reply With Quote
 
 
 
 
Janwillem Borleffs
Guest
Posts: n/a
 
      02-05-2004

"DeadCert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi, How can I store all my scripts on a separate page and then call
> them from the html page that I want to use them on? the <head> section
> is getting too cluttered and I would like to store all in one place.
> Anyone know how? Cheers


<script type="text/javascript" src="some.js"></script>

Where some.js contains JS code only.


JW



 
Reply With Quote
 
 
 
 
Bas Cost Budde
Guest
Posts: n/a
 
      02-05-2004
Janwillem Borleffs wrote:

>>Hi, How can I store all my scripts on a separate page and then call
>>them from the html page that I want to use them on? the <head> section
>>is getting too cluttered and I would like to store all in one place.

>
> <script type="text/javascript" src="some.js"></script>
>
> Where some.js contains JS code only.


If the OP has several files of javascript already, that doesn't compress
to one statement, right? I tried this once--I found nothing to include
javascript from another javascript file, I seem to need a SCRIPT tag for
every file. Correct me if I'm wrong. I love to be wrong on such issues

--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

 
Reply With Quote
 
Brian Genisio
Guest
Posts: n/a
 
      02-05-2004
Bas Cost Budde wrote:

> Janwillem Borleffs wrote:
>
>>> Hi, How can I store all my scripts on a separate page and then call
>>> them from the html page that I want to use them on? the <head> section
>>> is getting too cluttered and I would like to store all in one place.

>>
>>
>> <script type="text/javascript" src="some.js"></script>
>>
>> Where some.js contains JS code only.

>
>
> If the OP has several files of javascript already, that doesn't compress
> to one statement, right? I tried this once--I found nothing to include
> javascript from another javascript file, I seem to need a SCRIPT tag for
> every file. Correct me if I'm wrong. I love to be wrong on such issues
>


You are correct, but there is one solution that comes to mind (I am sure
there are others)...

myHtml.html:
<script type="text/javascript" src="some.js"></script>

some.js:
function writeScript( JSfile )
{
document.write("<script type='text/javascript' src='" +
JSfile + "'></scr" + "ipt>");
}

writeScript("file1.js");
writeScript("file2.js");
writeScript("file3.js");
....

 
Reply With Quote
 
Janwillem Borleffs
Guest
Posts: n/a
 
      02-05-2004

"Bas Cost Budde" <(E-Mail Removed)> wrote in message
news:bvt5n2$6ak$(E-Mail Removed)...
> If the OP has several files of javascript already, that doesn't compress
> to one statement, right? I tried this once--I found nothing to include
> javascript from another javascript file, I seem to need a SCRIPT tag for
> every file. Correct me if I'm wrong. I love to be wrong on such issues
>


You can include one js file, which includes the required files by document
writing the appropriate script tags.

Anyways, the OP would benefit from a thorough re-organisation of his
files...


JW




 
Reply With Quote
 
F. Da Costa
Guest
Posts: n/a
 
      02-05-2004
DeadCert wrote:

> Hi, How can I store all my scripts on a separate page and then call
> them from the html page that I want to use them on? the <head> section
> is getting too cluttered and I would like to store all in one place.
> Anyone know how? Cheers

I'm doing exactly the same using frames.
One of them is reserved for js only.

It has an additional (could be significant) benefit and that is that you
can also 'store' interpage states here. So loading a page with knowledge
about its previous state/ predecessor becomes possible as well.
Try and do this with a js variable in the page and then reloading it!

The js frame thus becomes like a library of sorts that is always accessible
from anywhere within the browser.

I'm sure there are people that won't like this but it works for me & very
well so I might add.
My 2c

Cheers,
Fermin DCG
 
Reply With Quote
 
Bas Cost Budde
Guest
Posts: n/a
 
      02-05-2004
Brian Genisio wrote:

> Bas Cost Budde wrote:
>
>> If the OP has several files of javascript already, that doesn't
>> compress to one statement, right? I tried this once--I found nothing
>> to include javascript from another javascript file, I seem to need a
>> SCRIPT tag for every file. Correct me if I'm wrong. I love to be wrong
>> on such issues

>
> You are correct, but there is one solution that comes to mind (I am sure
> there are others)...
>
> myHtml.html:
> <script type="text/javascript" src="some.js"></script>
>
> some.js:
> function writeScript( JSfile )
> {
> document.write("<script type='text/javascript' src='" +
> JSfile + "'></scr" + "ipt>");
> }
>
> writeScript("file1.js");
> writeScript("file2.js");
> writeScript("file3.js");
> ...
>

Now isn't it so that document.write replaces the existing content? That
is rather harsh for what I have in mind.

--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

 
Reply With Quote
 
Brian Genisio
Guest
Posts: n/a
 
      02-05-2004

>>

> Now isn't it so that document.write replaces the existing content? That
> is rather harsh for what I have in mind.
>


That is incorrect... in this context. document.write works differently
in two distinctively different contexts:

1. While the page is still parsing... Everything written is appended
after the current script tag, and then parsed into the document

2. After the page has parsed, ie: an action has occured (such as onLoad,
onClick, etc)... In this case, it overwrites everything.

The context I gave, is of type 1. If you do it in inline scripting, you
have nothing to fear.

To clarify:

<SCRIPT ...> document.writeln(...) </SCRIPT>

will append after the script tag

<SCRIPT ...> function ABC(...) { document.writeln(...); } </SCRIPT>
<a href=... onClick="ABC(...)">...</a>

will wipe out the page with the new text, when the link is clicked

Brian

 
Reply With Quote
 
Bas Cost Budde
Guest
Posts: n/a
 
      02-05-2004
Thank you.
--
Bas Cost Budde
http://www.heuveltop.nl/BasCB

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:27 AM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:26 AM
Using separate classpaths for separate classes? Frank Fredstone Java 1 06-27-2006 06:46 AM
How to separate content and scripts? tochiromifune HTML 0 12-30-2005 10:30 AM
How to use several separate classes (separate files) to be executed in one class (another file) EvgueniB Java 1 12-15-2003 01:18 AM



Advertisments