I am learning JavaScript at [url]http://www.w3schools.com/js/default.asp[/url]. This tutorial is very helpful because each lesson in the tutorial gives you an area where you can modify JavaScript code and execute the code to see the results.
But how do I execute a JavaScript program directly by my browser? How can I execute a JavaScript program so that the results appear in a new page in my IE browser?
Then, it's possible to use the console to verify some result in your browser (open the console with F12 with Internet Explorer or Chrome and in the developer's Tools for the others)
In your javascript code, some lines like : [CODE]if (window.console) console.log("myVar:"+someVariable+" myObject:" +JSON.stringify(someobject))[/CODE] will display the corresponding results if the console is open.
function dene() { var ifr = document.getElementById("iframeResult"); ifr.contentWindow.document.open('text/html','replace'); var text = document.getElementById("textareaCode").value; ifr.contentWindow.document.write(text); ifr.contentWindow.document.close(); } <br/> </script>
</head> <body> <div>Edit the code and click "Submit" to see the result.<input type="button" value="Submit" onclick="dene()"></div> <table> <tr><td>Code</td><td>Result</td></tr><tr><td> <textarea autocomplete="off" class="code_input" id="textareaCode" wrap="logical" rows="24" cols="50"><!DOCTYPE html> <html> <body>
<h1>My First JavaScript</h1>
<button type="button" onclick="document.getElementById('demo').innerHTML = Date()"> Click me to display Date and Time.</button>
@dschwartauthorNov 06.2014 — #Oh, now I think I see, JavaScript is always executed in an HTML page? So, to execute javaScript, just load the HTML page that has the script?