/    Sign up×
Community /Pin to ProfileBookmark

Executing JS code

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?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@007JulienNov 05.2014 — See this page to execute javascript programs in your 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.
Copy linkTweet thisAlerts:
@dschwartauthorNov 05.2014 — Which page?
Copy linkTweet thisAlerts:
@Ay__351_eNov 05.2014 — http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst


page.htm

<!DOCTYPE html>
<html>
<head>
<title>Tryit Editor v2.1</title>
<head>
<style type="text/css">
table {width:800px;height:200px}

#iframeResult {
background-color: #ffffff;
height:400px;
width:400px;
border:1px solid #d3d3d3;
border-radius:5px;
}
</style>

<script type="text/javascript">
// http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst
// http://www.webdeveloper.com/forum/showthread.php?302695-beginner-question
// http://www.w3schools.com/tags/att_iframe_width.asp

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/>
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;Edit the code and click "Submit" to see the result.&lt;input type="button" value="Submit" onclick="dene()"&gt;&lt;/div&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Code&lt;/td&gt;&lt;td&gt;Result&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
&lt;textarea autocomplete="off" class="code_input" id="textareaCode" wrap="logical" rows="24" cols="50"&gt;&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;My First JavaScript&lt;/h1&gt;

&lt;button type="button"
onclick="document.getElementById('demo').innerHTML = Date()"&gt;
Click me to display Date and Time.&lt;/button&gt;

&lt;p id="demo"&gt;&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;/textarea&gt;
&lt;/td&gt;&lt;td&gt;
&lt;iframe id="iframeResult" frameborder="2" name="view" src="deneme.htm"&gt;&lt;/iframe&gt; <br/>
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;


deneme.htm
&amp;nbsp;

this code is working in ie 8 and firefox 32.01
Copy linkTweet thisAlerts:
@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?
Copy linkTweet thisAlerts:
@Ay__351_eNov 07.2014 — I wrote

<iframe id="iframeResult" frameborder="2" name="view" ></iframe>

instead of

<iframe id="iframeResult" frameborder="2" name="view" [COLOR="#FF0000"]src="deneme.htm[/COLOR]"></iframe>

click button, see result


I wrote

<iframe id="iframeResult" frameborder="2" name="view"></iframe>


<script type="text/javascript">

dene();

</script>

instead of

<iframe id="iframeResult" frameborder="2" name="view" ></iframe>



Code appears in iframe
Copy linkTweet thisAlerts:
@alfredbillMay 14.2018 — Hope this will help you...

http://net-informations.com/js/basics/first.htm
Copy linkTweet thisAlerts:
@rootMay 14.2018 — @alfredbill#1592022 PLEASE note that this subject is OVER 4 Years OLD.

Please do not resurrect old posts.

Thank You.
Copy linkTweet thisAlerts:
@rootMay 14.2018 — {"locked":true}
×

Success!

Help @dschwart spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...