Jump to content

External Scripts


the-kid3210
 Share

Recommended Posts

Normally I don't do forums since the internet is full of flamers and really mean people that have a severe case of "brutal honesty" to most people but getting over that I have to ask.I want to make a JavaScript for a each site page I'm working on at the moment, I read that it doesn't require the script tag, but when I notepad the syntax, I keep getting this message that says I got a syntax error in Line 1, Char 1, some code 800A03EA with the Source saying something about a JScript compilation.The syntax includes:

<html><head></head><body>document.write("Rover")</body></html>

I tried to do it without inputting the <script> tag but I am still getting an error, can you guys help me figure out what I'm doing wrong because I'm at wits end.

Link to comment
Share on other sites

[...] I want to make a JavaScript for a each site page I'm working on at the moment, I read that it doesn't require the script tag [...]
I haven't heard of that--wonder where you saw it, as it sounds like a misunderstanding to me and you will need to include a script tag, otherwise that "document.write" line is just part of the body text. Have a look at the w3schools info if you need more info about the script tag.
Link to comment
Share on other sites

what I mean to say is that I need the syntax for an external JavaScript...I read on the site that in order to make an external script, the <script> tag must be taken awayI take my <script> tags away and it's still saying that I'm doing it wrong...I need help

Link to comment
Share on other sites

What that means is that your external javascript doesn't require the script tag. But your web page does.External script:document.write("Rover");Web Page<html><head><script type="text/javascript" src="script.js"></script></head><body></body></html>

Link to comment
Share on other sites

so pretty much just type in the script and save it under the ".js" extension?
Yes, and from the HTML, specify the full name of the file, as shown above.
Link to comment
Share on other sites

man, I feel really dumb, I wrote down some simple text but when I click on it to edit it, I still get this alert saying that I made a syntax error

document.write("Rover")

^I saved that under "javascript.js" and I'm still getting an alert that says this:Script: (name of file)Line: 1Char: 1Error: 'document' is undefinedCode: 800A1391Source: Microsoft JScript runtime error

Link to comment
Share on other sites

man, I feel really dumb, I wrote down some simple text but when I click on it to edit it, I still get this alert saying that I made a syntax error
document.write("Rover")

^I saved that under "javascript.js" and I'm still getting an alert that says this:Script: (name of file)Line: 1Char: 1Error: 'document' is undefinedCode: 800A1391Source: Microsoft JScript runtime error

If it says that, then it seems to be finding your script file, so I presume you must have correctly used the same name "javascript.js" in your actual html. What browser are you using to view the html? Internet Explorer? Which version?
Link to comment
Share on other sites

If it says that, then it seems to be finding your script file, so I presume you must have correctly used the same name "javascript.js" in your actual html. What browser are you using to view the html? Internet Explorer? Which version?
To view the HTML, I use IE6(?)
Link to comment
Share on other sites

To view the HTML, I use IE6(?)
Are you using any kind of webserver? I assume not at the moment, and you're just browsing the html file on your local disk?I tried IE6, IE7 and Firefox, and did not get any problem with that code.I wonder if you have an older version of IE6 than me, and the behaviour is different (so the document object does not yet exist at that point). Try changing your script, by putting this line in instead, so it doesn't use the document object:
alert('hello, world')

If still having problems, suggest you re-post your html and script here as they are now, just in case... :)

Link to comment
Share on other sites

I tried your coding but so far I'm still getting the same thing -.-my browser is IE4 (just checked it) and the script is opened by something called "Microsoft ® Windows Based Script Host" and so far it keeps giving me the same issue -.-I can't upload it on here but here's the script:

alert('hello, world')

Link to comment
Share on other sites

[...] my browser is IE4 (just checked it) [...]
IE4 is a very old browser! That's why you're seeing this different behaviour. You can get a new browser as a free download (for instance Firefox or IE7). If you're serious about doing some web development I recommend you do this first of all, as the technology has moved on a lot since the days of IE4.
Link to comment
Share on other sites

you mean to tell me I have to load up a new browser to check my script? I thought I only had to use my browser to check my HTML (don't remember reading that on the JavaScript portion of W3)...

Link to comment
Share on other sites

You can use only the browser. If you want to use IE4, you are testing if your script is compatible with IE4. It might be that IE4 does not instantiate the document object until after the page is finished loading. It might also be that you're trying to double-click the Javascript file to run it with Windows Script Host instead of the browser, in which case the document object will not exist at all. IE4 was released in 1997, so it's a 10-year old browser. I was writing Javascript for IE4/Netscape4 and those days were terrible, neither browser had good support for Javascript, and they rarely did the same thing. It's not going to be very helpful for you to try and run modern code on a browser that doesn't support it. People don't use IE4 any more so Javascript developers don't stretch to support it, it's not worthwhile to try and support a browser that, according to thecounter.com, is being used by only 0.07% of internet users in October. If you want to practice programming you would be well-advised to use a browser that supports the modern specifications, such as Firefox, Opera, or Safari.Basically, use anything but IE4. The only thing worse then IE4 is Netscape 4.

Link to comment
Share on other sites

IE4 is a very old browser! That's why you're seeing this different behaviour. You can get a new browser as a free download (for instance Firefox or IE7). If you're serious about doing some web development I recommend you do this first of all, as the technology has moved on a lot since the days of IE4.
Does CSS work in IE4?
Link to comment
Share on other sites

CSS 1 does I think, but with many bugs... and doesn't IE 4 still use the document.all property exclusively?

Link to comment
Share on other sites

Well, suffice it to say that the reason you see all the BS "browser detection" Javascript code today is because of the differences between IE4 and NS4 10 years ago (I'll leave it as an excersize to the reader to figure out how checking for "document.all" does not check if the browser is IE). Those browsers basically turned me off of Javascript for anything other then cosmetic things, today Javascript is actually useful because the browsers tend to support a lot of the same functionality, if not the exact same way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...