Click to See Complete Forum and Search --> : basic protocol for a .js file
dsdsdsdsd
05-07-2004, 09:14 AM
hello;
I have never written a stand-alone javascript (.js file);
if I create a file, new.js, and include the function document.write("hello"); I get an error;
I conclude that I am missing some structural protocol in the file;
any thoughts>
thank you
Shannon Burnett
ASheville NC USA
Pittimann
05-07-2004, 09:18 AM
Hi!
There's nothing wrong with that line! Do you have more code and maybe some HTML including the one calling the js file?
Cheers - Pit
dsdsdsdsd
05-07-2004, 09:25 AM
hello Pittimann;
actually I was just doble-clicking the new.js file icon that sits in 'My Documents';
thanks
Pittimann
05-07-2004, 09:31 AM
Hi!
You'll have to create an HTML document calling the js file; short example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript" src="new.js">
</script>
</head>
<body>
</body>
</html>
Just save it as an .htm or .html file in the same folder like the js file and try double clicking the htm(l) file...
Cheers - Pit
AdamGundry
05-07-2004, 03:22 PM
If you write a standalone JS file it is interpreted on Windows by the Windows Script Host (WSH). Because it is not run in a browser, you do not have access to DOM objects such as document or window, so different techniques are used. However, you can do things like file access which are not possible in the browser.
Check out the Microsoft documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsoriWindowsScriptHost.asp).
Adam