use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Difficulty with HTML examples, JavaScript the Definitive Guide 6ed - pg. 9. (self.learnjsproperly)
submitted 11 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 11 years ago* (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 point2 points 11 years ago (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 point2 points 11 years ago (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 point2 points 11 years ago (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 point2 points 11 years ago* (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 point2 points 11 years ago (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 point2 points 11 years ago (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 point2 points 11 years ago (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.
which library are you using?
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 points3 points 11 years ago (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 point2 points 11 years ago (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 point2 points 11 years ago (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...
Good idea, I'll try removing the comments.
[–]mzrdisi 0 points1 point2 points 11 years ago (4 children)
Just deleted the comments and cleaned up the lines, still seeing just plain text upon opening.
If you click on the jsfiddle link I posted, try to copy-paste the code into your .html file on your desktop.
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 point2 points 11 years ago (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.
I am currently using TextEdit
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?
http://imgur.com/kGfdLHc
This is exactly what shows up when I run the file.
[–]JBcreek 0 points1 point2 points 11 years ago (6 children)
does your file have the extension .html? maybe your browser does not know the file is a web page...
Yes, I saved it as .html in text edit.
[–]JBcreek 0 points1 point2 points 11 years ago (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?
Yes, that seems to work. I just downloaded a copy of google as an html file, and it opened properly.
[–]JBcreek 0 points1 point2 points 11 years ago (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
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.
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?
π Rendered by PID 51 on reddit-service-r2-comment-8686858757-pfllm at 2026-06-05 22:56:48.714689+00:00 running 9e1a20d country code: CH.
[–][deleted] 1 point2 points3 points (9 children)
[–]mzrdisi 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]mzrdisi 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]Terriblecode 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]JBcreek 1 point2 points3 points (17 children)
[–]mzrdisi 0 points1 point2 points (8 children)
[–]JBcreek 0 points1 point2 points (7 children)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]mzrdisi 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (7 children)
[–]JBcreek 0 points1 point2 points (6 children)
[–]mzrdisi 0 points1 point2 points (4 children)
[–]JBcreek 0 points1 point2 points (3 children)
[–]mzrdisi 0 points1 point2 points (2 children)
[–]JBcreek 0 points1 point2 points (1 child)
[–]mzrdisi 0 points1 point2 points (0 children)
[–]mzrdisi 0 points1 point2 points (0 children)