Easy Webbers About Authors Contact Us Advertise Login


Ads by AdBrite.

How to add JavaScript to your website

Posted by Simon on February 21st, 2007 in JavaScript

Adding JavaScript to your site is very easy. You can do it using four different methods.

Add this script tag in your web document:

‹script type="text/javascript"›
// Your code here
‹/script›

If you want to support older brosers or if you use transitional XHTML, the more stricter version of HTML you should use this code:

‹script type="text/javascript"›
‹!--
// Your code here
-->
‹/script›

In Strict XHTML you will need to use the CDATA commenting syntax to comment out your code:

‹script type="text/javascript"›
// ‹ ![CDATA[
// Your code here
// ]]›
‹/script›

The best way to add JavaScript to your site when using XHTML is to add the JavaScript in it’s own document (.js) and link it in using this line of code placed in your header:

‹code›‹script type="text/javascript" xsrc="the link to the JavaScript file.js"›‹/script›‹/code›

AddThis Social Bookmark Button

Get paid to review this post: Earn $7.50 by making a review about this post on your own blog. Click here for more information!

2 Responses to “How to add JavaScript to your website”

  1. ProBlogger » How to add JavaScript to your website Says:

    [...] Original post by Simon and software by Elliott [...]

  2. Responsible Blogging at its Finest Says:

    Thank you for the tutorial,

    but could you please add some links to where I could ascertain some Javascript? Premade please, thanks :)

Leave a Reply