If a browser does not recognize the <script> tag, it will display the tag’s content on the page in a textual format. To prevent the browser from doing this, you should hide the script in comment tags.Such a browser will ignore the comment and it will not write the tag’s content on the page, while a new browser will understand that the script should be executed, even if it is surrounded by comment tags.
Example
JavaScript:
<script>
<!–
document.write(”Hello World!”)
//–>
</script>
VBScript:
<script >
<!–
document.write(”Hello World!”)
‘–>
</script> |
The <noscript> Tag
Instead of commenting out the scripts we can use the <noscript> tag
The <noscript> tag is used to define an alternate text if a script is not understood and executed by the browser. This tag is used for browsers that recognize the <script> tag, but do not support the script inside, so these browsers will display the text inside the <noscript> tag instead.If a browser supports the script inside the <script> tag it will ignore the <noscript> tag.
Example
JavaScript:
<script>
<!–
document.write(”Hello World!”)
//–>
</script>
<noscript>Your browser does not support JavaScript!</noscript>
VBScript:
<script >
<!–
document.write(”Hello World!”)
‘–>
</script>
<noscript>Your browser does not support VBScript!</noscript> |
Script Tags
| Tag |
Description |
| <script> |
Defines a script |
| <noscript> |
Defines an alternate text if the script is not executed |
| <object> |
Defines an embedded object |
| <param> |
Defines run-time settings (parameters) for an object |
| <applet> |
Deprecated. Use <object> instead |
HTML 4.0 Standard Attributes
All HTML tags have attributes. The special attributes for each tag are listed under each tag description. The attributes listed here are the core and language attributes that are standard for all tags (with a few exceptions):
Core Attributes
| Attribute |
Value |
Description |
| class |
class_rule or style_rule |
The class of the element |
| id |
id_name |
A unique id for the element |
| style |
style_definition |
An inline style definition |
| title |
tooltip_text |
A text to display in a tool tip |
Note: Not valid in base, head, html, meta, param, script, style, and title elements.
Language Attributes
| Attribute |
Value |
Description |
| dir |
ltr | rtl |
Sets the text direction |
| lang |
language_code |
Sets the language code |
Note: Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.
Keyboard Attributes
| Attribute |
Value |
Description |
| accesskey |
character |
Sets a keyboard shortcut to access an element |
| tabindex |
number |
Sets the tab order of an element |
HTML 4.0 Event Attributes
New to HTML 4.0 is the ability to let HTML events trigger actions in the browser, like starting a JavaScript when a user clicks on an HTML element. Below is a list of attributes that can be inserted into HTML tags to define event actions.
Window Events
Only valid in body and frameset elements.
| Attribute |
Value |
Description |
| onload |
script |
Script to be run when a document loads |
| onunload |
script |
Script to be run when a document unloads |
Form Element Events
Only valid in form elements.
| Attribute |
Value |
Description |
| onchange |
script |
Script to be run when the element changes |
| onsubmit |
script |
Script to be run when the form is submitted |
| onreset |
script |
Script to be run when the form is reset |
| onselect |
script |
Script to be run when the element is selected |
| onblur |
script |
Script to be run when the element loses focus |
| onfocus |
script |
Script to be run when the element gets focus |
Keyboard Events
| Attribute |
Value |
Description |
| onkeydown |
script |
What to do when key is pressed |
| onkeypress |
script |
What to do when key is pressed and released |
| onkeyup |
script |
What to do when key is released |
Note:Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.
Mouse Events
| Attribute |
Value |
Description |
| onclick |
script |
What to do on a mouse click |
| ondblclick |
script |
What to do on a mouse double-click |
| onmousedown |
script |
What to do when mouse button is pressed |
| onmousemove |
script |
What to do when mouse pointer moves |
| onmouseout |
script |
What to do when mouse pointer moves out of an element |
| onmouseover |
script |
What to do when mouse pointer moves over an element |
| onmouseup |
script |
What to do when mouse button is released |
Note: Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, title elements.
HTML URL Encoding
URL encoding converts characters into a format that can be safely transmitted over the Internet.
URL – Uniform Resource Locator
The address that we type in a browser to open a page is called a URL. All the webpages available on the internet are recognised by this URL only. There is a unique URL for each and every page.Web browsers request pages from web servers by using a URL.
The URL is the address of a web page like: http://www.xyz.com.
URL Encoding
URLs are sent over the Internet using the ASCII character-set only.
Since URLs often contains characters outside the ASCII set, the URL has to be converted. URL encoding converts the URL into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with “%” followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.
URL Encoding Examples
| Character |
URL-encoding |
| € |
%80 |
| £ |
%A3 |
| © |
%A9 |
| ® |
%AE |
| À |
%C0 |
| Á |
%C1 |
| Â |
%C2 |
| Ã |
%C3 |
| Ä |
%C4 |
| Å |
%C5 |