Inline script works - but fails when included from .js file - why?

R

Randell D.

Folks,

I've found a nice menu piece of javascript that works fine when the code is
included entirely inside the html page. However, when I place the
javascript code outside, in its own ".js" type file, it doesn't execute.
IE6 reports an error "Object expected" line 30, char 1, code 0. This is the
BODY tag which I've pasted below (with carriage returns to make it easier to
read). I cannot understand as to how this line could be problematic though
since its the exact same in my 'inline' script which works.

<BODY marginwidth="0"
marginheight="0"
style="margin: 0"
onLoad="writeMenus()"
onResize="if (isNS4) nsResizeHandler()">

Why does it fail? How do I fix it? If it helps further, I have the code
uploaded and available at:

This is where the menu is 'inline'
http://www.wiredwords.net/a.htm

This is where the menu is included using <script src=></script> tags
http://www.wiredwords.net/b.htm

Thanks in advance,
Randell D.
 
F

Fabian

This is where the menu is included using <script src=></script> tags
http://www.wiredwords.net/b.htm

Change this:

<script src=/b.js></script>

To this:

<script src="b.js">
</script>

That carriage return seems to help for some browsers. Also get your
quoting right. And, unlike me, check to make sure you are actually
pointing to teh file's correct location.
 
R

Randell D.

Fabian said:
Change this:

<script src=/b.js></script>

To this:

<script src="b.js">
</script>

That carriage return seems to help for some browsers. Also get your
quoting right. And, unlike me, check to make sure you are actually
pointing to teh file's correct location.


--

Thanks for the quick response but... Nope... that didn't do it - IE now
reports the error on line 31 (since I placed a carriage return in like you
suggested) - this is the BODY tag. I also cleared my cache, re-tried and
rechecked my cache... The correct "b.js" file is loaded (and visable in my
cache)... But to cover myself, I actually said

<script src="http://www.wiredwords.net/b.js">
</script>

(thus I specified the full server path in the source).

Any other ideas? Scripts are still available on
http://www.wiredwords.net/a.htm (this works)
http://www.wiredwords.net/b.htm (this fails)

Also FYI... for some reason my Outlook Express asked me to download Japanese
character set to read your post... dunno if you knew this or if you have
some character that you have included in your signature....

thanks
 
G

Graham J

I've found a nice menu piece of javascript that works fine when the code
is
included entirely inside the html page. However, when I place the
javascript code outside, in its own ".js" type file, it doesn't execute.

You have left the <script ...> and </script> lines in your ".js" file. They
are HTML constructs and don't belong there. You just need the JavaScript.
 
F

Fabian

"Randell D." hu kiteb
Thanks for the quick response but... Nope... that didn't do it - IE now
reports the error on line 31 (since I placed a carriage return in like you
suggested) - this is the BODY tag. I also cleared my cache, re-tried and
rechecked my cache... The correct "b.js" file is loaded (and visable in my
cache)... But to cover myself, I actually said

<script src="http://www.wiredwords.net/b.js">
</script>

Unless it is actually on a different server, specifying teh full server
path is bad form, as some browsers won't cache properly that way. I
Also FYI... for some reason my Outlook Express asked me to download Japanese
character set to read your post... dunno if you knew this or if you have
some character that you have included in your signature....

I think your computer is getting lonely, and wants a few more fonts to
play with. DOwnload or not, you choose. I believe there is even an
option on the lines of dont ask me this again. I know I can change the
defaults, but msoe is so tightly integrated that it will cause all kinds
of not fun problems if I mess with that setting.
 
L

Lasse Reichstein Nielsen

Randell D. said:

Your Javascript file contains non-javascript text:
---
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Angus Turnbull -->
<!-- Web Site: http://gusnz.cjb.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
---
and
---
</script>
---
This is HTML, not Javascript.

The script HTML tag is used to include the content (which should be
Javascript) in an HTML document. When you have a stand-alone Jasascript
file, all of the content must be Javascript.

While browsers might allow HTML comments in Javascript, it is not
correct. Use Javascript comments instead.

/L
 
R

Randell D.

Lasse Reichstein Nielsen said:
Your Javascript file contains non-javascript text:
---
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Angus Turnbull -->
<!-- Web Site: http://gusnz.cjb.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
---
and
---
</script>
---
This is HTML, not Javascript.

The script HTML tag is used to include the content (which should be
Javascript) in an HTML document. When you have a stand-alone Jasascript
file, all of the content must be Javascript.

While browsers might allow HTML comments in Javascript, it is not
correct. Use Javascript comments instead.

/L
'Faith without judgement merely degrades the spirit divine.'


Many thanks for that!
 
R

Randell D.

Graham J said:
You have left the <script ...> and </script> lines in your ".js" file. They
are HTML constructs and don't belong there. You just need the JavaScript.

Many thanks for that!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top