wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes External .js files again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "External .js files again" Watch "External .js files again" New topic
Author

External .js files again

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, for some reason, when I include the LOC

inside my header script tag, the HTML page doesnt work correctly,
even though external.js file is blank.
Some of the page shows up, like the tables, but the
tables' cells aren't shown.

What I've now just done is use 2 header scripts, the first one uses
src="external.js", and the second doesn't, and it all functions correctly
again.

I'm unclear what is happening here, is it mandatory that functions
'imported' from external .js files be included in scripts separate
from the original scripts in a html page?

Thanks for any advice.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Are you closing the tag

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

the XHTML /> does not work with IE.

The js file should not include opening and closing <script> tags

Eric
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Basically, when I use...


it doesn't work right, and the tables cells are empty.

But... when I use...

There is no problem. I'm confused why the first code doesn't work
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

If you specify the src attribute to the script tag, the body of the script tag is ignored.

So don't mix and match them.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

From the HTML 4 spec:

The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the SCRIPT element.

[ February 26, 2006: Message edited by: Bear Bibeault ]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
So have I done that the correct way in the second piece of code, in my last post?
It seems wrong using scripts like that, so if I wanted to use functions from say external1.js and external2.js, as well as functions in the html
page, would I use...


Thanks again for your help
[ February 26, 2006: Message edited by: colin shuker ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: External .js files again