Saeed Posted November 15, 2010 Share Posted November 15, 2010 Good Day,Is it imperative to embed a JS script in an HTML page in order to execute the code? or is it possible to somehow run a script the way one would do a Java code from the command line? Link to comment Share on other sites More sharing options...
jeffman Posted November 15, 2010 Share Posted November 15, 2010 Did you try it? :)The W3C requires browsers to be VERY flexible and forgiving. They should try to render documents with no HTML or incorrect HTML as best they can. As long as you have <script> tags, code written between them should execute. Link to comment Share on other sites More sharing options...
boen_robot Posted November 15, 2010 Share Posted November 15, 2010 You can also execute JavaScript in the URL of any page. The code will run as if it's part of the current page.For example, type the following in your browser: java script:alert('There are '+document.getElementsByTagName('div').length+' "div" elements on this page.'); (NOTE: Remove the space between "java" and "script". The forum adds it for security reasons)As long as the code is one statement (possibly with closures... long story), you can do that.You can also open your browser's console and type there. On IE, press F12. Same on FF, but if you have Firebug installed. Link to comment Share on other sites More sharing options...
jeffman Posted November 15, 2010 Share Posted November 15, 2010 I test javascript snippets in my console all the time. I find it especially useful for testing regular expressions, because it's very easy (fast) to make small changes. Link to comment Share on other sites More sharing options...
Fmdpa Posted November 16, 2010 Share Posted November 16, 2010 For example, type the following in your browserThis forum has divitis! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.