Tweaking your Community

:)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

You are not connected. Please login or register

JS How To

Go down  Message [Page 1 of 1]

1JS How To Empty JS How To Thu Apr 22, 2010 2:43 am

iJerick

iJerick
Administrator
Administrator

Put a Javascript into an HTML page

(The example below shows how to use Javascript to write text on a web page:)
Code:

<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>

The example below shows how to add HTML tags to the Javascript:
Code:

<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
</body>
</html>

Example Explained[/br]

To insert a Javascript into an HTML page, we use the tag. Inside the tag we use the type attribute to define the scripting language.

So, the and tells where the Javascript starts and ends:
Code:

<html>
<body>
<script type="text/javascript">
...
</script>
</body>
</html>

The document.write command is a standard Javascript command for writing output to a page.

By entering the document.write command between the and tags, the browser will recognize it as a Javascript command and execute the code line. In this case the browser will write Hello World! to the page:
Code:

<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>

[b]How to Handle Simple Browsers


Browsers that do not support Javascript, will display Javascript as page content.

To prevent them from doing this, and as a part of the Javascript standard, the HTML comment tag should be used to "hide" the Javascript.

Just add an HTML comment tag (end of comment) after the last Javascript statement, like this:

Code:

<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>

The two forward slashes at the end of comment line (//) is the Javascript comment symbol. This prevents Javascript from executing the --> tag.

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

 



iJerick | Forumotion | Punbb | jQuery | CSS3
Copyright © 2011 TweakGround™. All Right Reserved.

Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com