And start as all programming exercises with writing a "hello world" script.
Up to line 6 there are usual XHTML beginning tags as you realize.
Real excitement is starting with the line 6 it includes "script" tag that
indicates the beginning of the script then we have " <!-- " html comment tag which is necessary to make your page available for the old browser that does not support JavaScript so comment tag makes your script comment for the olds. Thus your script is not shown at your page.
Line 8 includes a object (document) usage. It is provided by browsers. Then we use its ".writeln" function to write your string to your page's HTML. There is also ".write" function to be udes but it stays on same line but ".writeln" goes to next line at the end. In addition as you realize the string parameter of method is writing its corresponding HTML tags because as I said parameter of the method is writing to your page HTML.
NOTE!:Write functions can use special characters like " /n, /t, /" " as parameter.
Line 9 has "//" single line comment tag of JavaScript to have proper script to neglect "-->" comment tag for HTML. We have no "//" before "<!--" since it is also single line comment delimiter. Finally close your script.
We add our script to head section of our HTML to be executed before body part of HTML but it is also possible to use your script in body part of your html and we'll see how to use in such way but be patient :).

to copy pase!!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>First tutorial of JavaScript</title>
<script type="text/javascript">
<!--
document.writeln(" <h1> Hello World, This is Eren Golge! </h1>");
//-->
</script>
</head>
download the example page
Hiç yorum yok:
Yorum Gönder