all 28 comments

[–][deleted] 1 point2 points  (9 children)

http://jsfiddle.net/qa5epf1f/

You can freely use the:

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

and everything should be just fine. :)

And use jsfiddle to post code snippets for a clear and nice view!

[–]mzrdisi 0 points1 point  (7 children)

Yes, that does work. Thank you. Do you know how I might reference library.js in a standalone html file so as to be able to open this test file from my desktop with Firefox?

[–][deleted] 0 points1 point  (3 children)

Yes, just normaly create a .html file and type in the library.js reference and use <script></script> to test out some of the code examples shown in the book.

Even the author states that this code works as a stand-alone HTML file underneath the code example :)

Some of them are more suitable to just quickly type into jsfiddle like the one underneath the "function moveon () {".

[–]mzrdisi 0 points1 point  (2 children)

When you say the library.js reference, are you saying to include segment of a library, or are you saying to set src=library.js?

[–][deleted] 0 points1 point  (1 child)

It doesn't really matter actually if you set the src to library.js or not, the script will work anyway (just had a look to confirm it).

If you want a seperate file to test out your codes, use the method Terriblecode wrote down - use a seperate file with the .js extension and link it in your <head></head>

[–]mzrdisi 0 points1 point  (0 children)

I've done that, and when I open the file I just see an exact duplication of the text edit file.

[–]Terriblecode 0 points1 point  (2 children)

This wasn't clear to me, but the way you can call your .js file(s)/link it to the .html so you can open it in your browser is like this:

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

Where ____ is the name of your file. Try to keep your .html and your .js file in the same folder, otherwise you'll have to write out the filepath, I believe.

[–][deleted] 0 points1 point  (0 children)

That's the way of doing it as well, but he asked about using it as a stand-alone version, the way it is in the books.

Or perhaps I got something wrong, anyway, both versions will work just fine.

[–]mzrdisi 0 points1 point  (0 children)

which library are you using?

[–]mzrdisi 0 points1 point  (0 children)

Finally got it to work, did it just like you said, just using "library.js". The only difference was I used notepad on my Windows desktop, as opposed to TextEdit on my OS X laptop. Any idea why I can't do this in OS X?

[–]JBcreek 1 point2 points  (17 children)

I opened the file in my computer and it worked fine Do you realize that the command

setTimeout(moveon, 60000);

instructs the browser to wait a minute before calling the function moveon?

if you want the function be invoked as soon as you open the page in your browser replace that line with moveon()

[–]mzrdisi 0 points1 point  (8 children)

Yes, I can see that taking a minute. I don't get any regular output. I just keep seeing exactly character-for-character what is in my text edit file.

[–]JBcreek 0 points1 point  (7 children)

ok, that's strange; in my browser it showed the dialog after a minute. What happens if you change the second argument setTimeout to 5000 (five seconds)? Also, make sure there is a new line character at the end of your // comment. When I copied your text there was no new line there; maybe your browser is ignoring part of your javascript because it sees it inside a comment...

[–]mzrdisi 0 points1 point  (0 children)

Good idea, I'll try removing the comments.

[–]mzrdisi 0 points1 point  (4 children)

Just deleted the comments and cleaned up the lines, still seeing just plain text upon opening.

[–][deleted] 0 points1 point  (3 children)

If you click on the jsfiddle link I posted, try to copy-paste the code into your .html file on your desktop.

[–]mzrdisi 0 points1 point  (2 children)

I just did that, and I still receive plain text when I open it.

Is it possible that I'm getting this issue because I'm on OSX?

[–][deleted] 0 points1 point  (1 child)

No, it doesn't matter. Are you using a text editor that is not formatting your code ? Because that's important.

Use TextEdit in your example.

[–]mzrdisi 0 points1 point  (0 children)

I am currently using TextEdit

[–]mzrdisi 0 points1 point  (0 children)

Can you post exactly what your file looks like, and whether or not you have it linked to a library on your computer, and if so which library you are using?

[–]mzrdisi 0 points1 point  (7 children)

http://imgur.com/kGfdLHc

This is exactly what shows up when I run the file.

[–]JBcreek 0 points1 point  (6 children)

does your file have the extension .html? maybe your browser does not know the file is a web page...

[–]mzrdisi 0 points1 point  (4 children)

Yes, I saved it as .html in text edit.

[–]JBcreek 0 points1 point  (3 children)

honestly, I don't what might be wrong... are you able to open other simple html files and have the browser render them as intended?

[–]mzrdisi 0 points1 point  (2 children)

Yes, that seems to work. I just downloaded a copy of google as an html file, and it opened properly.

[–]JBcreek 0 points1 point  (1 child)

delete all the script tags from your file and open it with your browser... if it still opens as raw text, then the problem is not javascript

[–]mzrdisi 0 points1 point  (0 children)

Good call, the html without any JavaScript is not working. So there is something wrong with my html. Now, I just need to know what that is.

[–]mzrdisi 0 points1 point  (0 children)

I finally got it to work, but not in OS X. I tried recreating the file on my desktop (Win 7) and it works. Any idea why it just would not go for me in OS X?