Sunteți pe pagina 1din 50

Advanced HTML Concepts

eAbyas Info Solutions Version 1.0

LAYOUT
Web page layout is very important to give better look to your website. You should design your webpage layout very carefully. You may have noticed that there are many websites which have put their content in multiple columns - they are formatted like a magazine or newspaper. This is easily achieved by using tables or division or span tags. Sometime you use CSS as well to position various elements or to create backgrounds or colorful look for the pages.

HTML Layout - Using Tables:


The simplest and most popular way of creating layouts is using HTML <table> tag. These tables are arranged in columns and rows, so you can utilize these rows and columns in whatever way you like. For example, the following HTML layout example is achieved using a table with 3 rows and 2 columns - but the header and footer column spans both columns using the colspan attribute:
<table width="100%" border="0"> <tr> <td colspan="2" style="background-color:#CC99FF;"> <h1>This is Web Page Main title</h1> </td> </tr> <tr valign="top"> <td style="background-color:#FFCCFF; width:100px;text-align:top;"> <b>Main Menu</b><br /> HTML<br /> PHP<br /> PERL... </td> <td style="background-color:#eeeeee;height:200px; width:300px;text-align:top;"> Technical and Managerial Tutorials </td> </tr> <tr> <td colspan="2" style="background-color:#CC99FF;">

eAbyas Info Solutions

<center> Copyright 2007 Tutorialspoint.com </center> </td> </tr> </table>

This will produce following result: To Become more comfortable - Do Online Practice

This is Web Page Main title


Main Menu HTML PHP PERL... Technical and Managerial Tutorials

Multiuple Columns Layouts - Using Tables


You can design your webpage to put your web content in multiple pages. You can keep your content in middle column and you can use left column to use menu and right column can be used to put advertisement or some other stuff. It will be very similar to our site tutorialspoint.com.

Copyright 2007 Tutorialspoint.com

Here is an example to create three column layout:


<table width="100%" border="0"> <tr valign="top"> <td style="background-color:#FFCCFF;width:20%; text-align:top;"> <b>Main Menu</b><br /> HTML<br /> PHP<br /> PERL... </td> <td style="background-color:#eeeeee;height:200px; width:60%;text-align:top;"> Technical and Managerial Tutorials

eAbyas Info Solutions

</td> <td style="background-color:#FFCCFF; width:20%;text-align:top;"> <b>Right Menu</b><br /> HTML<br /> PHP<br /> PERL... </td> </tr> <table>

This will produce following result:


Main Menu Technical and Managerial Tutorials HTML PHP PERL... Right Menu HTML PHP PERL...

HTML Layouts - Using DIV, SPAN


The div element is a block level element used for grouping HTML elements. While the div tag is a block-level element, the HTML span element is used for grouping elements at an inline level. Although we can achieve pretty nice layouts with HTML tables, tables weren't really designed as a layout tool. Tables are more suited to presenting tabular data. You can achieve same result whatever you have achieved using <table> tag in previous example.
<div style="width:100%"> <div style="background-color:#CC99FF;"> <b style="font-size:150%">This is Web Page Main title</b> </div>

eAbyas Info Solutions

<div style="background-color:#FFCCFF; height:200px;width:100px;float:left;"> <b>Main Menu</b><br /> HTML<br /> PHP<br /> PERL... </div> <div style="background-color:#eeeeee; height:200px;width:300px;float:left;"> Technical and Managerial Tutorials </div> <div style="background-color:#CC99FF;clear:both"> <center> Copyright 2007 Tutorialspoint.com </center> </div> </div>

This will produce following result:

This is Web Page Main title


Main Menu HTML PHP PERL...

eAbyas Info Solutions

DOCTYPE
Document Type Declaration
From Wikipedia, the free encyclopedia Jump to: navigation, search

A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML or XML document (for example, a webpage) with a Document Type Definition (DTD) (for example, the formal definition of a particular version of HTML). In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax. The HTML layout engines in modern web browsers perform DOCTYPE "sniffing" or "switching", wherein the DOCTYPE in a document served as text/html determines a layout mode, such as "quirks mode" or "standards mode". The text/html serialization of HTML5, which is not SGML-based, uses the DOCTYPE only for mode selection. Since web browsers are implemented with special-purpose HTML parsers, rather than general-purpose DTD-based parsers, they don't use DTDs and will never access them even if a URL is provided. The DOCTYPE is retained in HTML5 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers.[ A <!DOCTYPE> declaration helps the browser to display a web page correctly.

Syntax
The general syntax for a document type declaration is:
<!DOCTYPE root-element PUBLIC "FPI" ["URI"] [ <!-- internal subset declarations --> ]>

or
<!DOCTYPE root-element SYSTEM "URI" [ <!-- internal subset declarations --> ]>

eAbyas Info Solutions

In XML, the root element that represents the document is the first element in the document. For example, in XHTML, the root element is <html>, being the first element opened (after the doctype declaration) and last closed. The keywords SYSTEM and PUBLIC suggest what kind of DTD it is (one that is on a private system or one that is open to the public). If the PUBLIC keyword is chosen then this keyword is followed by a restricted form of "public identifier" called Formal Public Identifier (FPI) enclosed in double quote marks. After that, necessarily, a "system identifier" enclosed in double quote marks, too, is provided. For example, the FPI for XHTML 1.1 is "-//W3C//DTD XHTML 1.1//EN" and, there are 3 possible system identifiers available for XHTML 1.1 depending on the needs, one of them is the URI reference "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd". If, instead, the SYSTEM keyword is chosen, only a system identifier must be given. It means that the XML parser must locate the DTD in a system specific fashion, in this case, by means of a URI reference of the DTD enclosed in double quote marks. The last part, surrounded by literal square brackets ([]), is called an internal subset which can be used to add/edit entities or add/edit PUBLIC keyword behaviours.[2] The internal subset is always optional (and sometimes even forbidden within simple SGML profiles, notably those for basic HTML parsers that don't implement a full SGML parser). On the other hand, document type declarations are slightly different in SGML-based documents such as HTML, where you may associate the public identifier with the system identifier. This association might be performed, e. g., by means of a catalog file resolving the FPI to a system identifier.[3]

Example
The first line of many World Wide Web pages reads as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="ar" dir="rtl" xmlns="http://www.w3.org/1999/xhtml">

This Document Type Declaration for XHTML includes by reference a DTD, whose public identifier is -//W3C//DTD XHTML 1.0 Transitional//EN and whose system identifier is http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd. An entity resolver may use either identifier for locating the referenced external entity. No internal subset has been indicated in this example or the next ones. The root element is declared to be html and, therefore, it is the first tag to be opened after the end of the doctype declaration in this example and the next ones,

eAbyas Info Solutions

too. The html tag is not part of the doctype declaration but has been included in the examples for orientation purposes.

HTML 4.01 DTDs


Strict DTD does not allow presentational markup with the argument that Cascading Style Sheets should be used for that instead. This is how the Strict DTD looks:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>

Transitional DTD allows some older PUBLIC and attributes that have been deprecated:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>

If frames are used, the Frameset DTD must be used instead, like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html>

XHTML 1.0 DTDs


XHTML's DTDs are also Strict, Transitional and Frameset. XHTML Strict DTD. No deprecated tags are supported and the code must be written correctly.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

eAbyas Info Solutions

The <!DOCTYPE> Declaration


There are many different documents on the web. A browser can only display a document correctly, if it knows what kind of document it is. There are also many different versions of HTML, and a browser can only display an HTML page 100% correctly if it knows the exact HTML version used in the page. This is what <!DOCTYPE> is used for. <!DOCTYPE> is not an HTML tag. It is an information (a declaration) to the browser about what version the HTML is written in. In this tutorial we use the HTML5 DOCTYPE.

Example
An HTML document with an HTML5 DOCTYPE: <!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> The content of the document...... </body> </html>

eAbyas Info Solutions

10

Common Declarations
HTML5
<!DOCTYPE html>

HTML 4.01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

XHTML 1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Choosing a DOCTYPE
According to HTML standards, each HTML document requires a document type declaration. The "DOCTYPE" begins the HTML document and tells a validator which version of HTML to use in checking the document's syntax. If standard HTML does not meet your needs but you still wish to gain the benefits of HTML validation, see the section on using a custom DTD. The following DOCTYPEs are commonly used:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

eAbyas Info Solutions

11

This declares the document to be HTML 4.01 Strict. HTML 4.01 Strict is a trimmed down version of HTML 4.01 that emphasizes structure over presentation. Deprecated elements and attributes (including most presentational attributes), frames, and link targets are not allowed in HTML 4 Strict. By writing to HTML 4 Strict, authors can achieve accessible, structurally rich documents that easily adapt to style sheets and different browsing situations. However, HTML 4 Strict documents may look bland on very old browsers that lack support for style sheets. Newer browsers such as Internet Explorer 5 for Mac, Netscape 6, and Mozilla use a standards-compliant rendering for HTML 4 Strict documents. These browsers use a "quirks" mode for most other document types to emulate rendering bugs in older browsers.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

This declares the document to be HTML 4.01 Transitional. HTML 4 Transitional includes all elements and attributes of HTML 4 Strict but adds presentational attributes, deprecated elements, and link targets. Newer browsers such as Internet Explorer 5 for Mac, Netscape 6, and Mozilla use a standards-compliant rendering for HTML 4.01 Transitional documents that include the URI of the DTD in the DOCTYPE. These browsers use a "quirks" mode to emulate rendering bugs in older browsers if the URI is omitted:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

This declares the document to be HTML 4.01 Frameset. HTML 4 Frameset is a variant of HTML 4 Transitional for documents that use frames.

eAbyas Info Solutions

12

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

This declares the document to be XHTML 1.0 Strict. XHTML 1.0 Strict is an XML version of HTML 4 Strict.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

This declares the document to be XHTML 1.0 Transitional. XHTML 1.0 Transitional is an XML version of HTML 4 Transitional.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

This declares the document to be XHTML 1.0 Frameset. XHTML 1.0 Frameset is an XML version of HTML 4 Frameset.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

This declares the document to be HTML 3.2. HTML 3.2 is well supported by most browsers in use. However, HTML 3.2 has limited support for style sheets and no support for HTML 4 features such as frames and internationalization.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

This declares the document to be HTML 2.0. HTML 2.0 is widely supported by browsers but lacks support for tables, frames, and internationalization, as well as many commonly used presentational elements and attributes.

URL - Uniform Resource Locator


A URL is another word for a web address.

eAbyas Info Solutions

13

A URL can be composed of words, such as "w3schools.com", or an Internet Protocol (IP) address: 192.68.20.50. Most people enter the name of the website when surfing, because names are easier to remember than numbers. When you click on a link in an HTML page, an underlying <a> tag points to an address on the world wide web. A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web. A web address, like this: http://www.w3schools.com/html/default.asp follows these syntax rules: scheme://host.domain:port/path/filename Explanation:

scheme - defines the type of Internet service. The most common type is http host - defines the domain host (the default host for http is www) domain - defines the Internet domain name, like w3schools.com :port - defines the port number at the host (the default port number for http is 80) path - defines a path at the server (If omitted, the document must be stored at the root directory of the web site) filename - defines the name of a document/resource

Common URL Schemes


The table below lists some common schemes: Scheme http https ftp Short for.... HyperText Transfer Protocol Secure HyperText Transfer Protocol File Transfer Protocol Which pages will the scheme be used for... Common web pages starts with http://. Not encrypted Secure web pages. All information exchanged are encrypted For downloading or uploading files to a website. Useful for domain maintenance

eAbyas Info Solutions

14

file URLs typically consist of three pieces:

A file on your computer

1. The name of the protocol used to transfer the resource over the Web. 2. The name of the machine hosting the resource. 3. The name of the resource itself, given as a path.

Consider the URL that designates the current HTML specification:


http://www.w3.org/TR/WD-html4/cover.html

This URL may be read as follows: Use the HTTP protocol to transfer the data residing on the machine www.w3.org in the file /TR/WD-html4/cover.html URLs in general are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive. /u The character set of URLs that appear in HTML is specified in [RFC1738].

Fragment URLs
The URL specification en vigeur at the writing of this document ([RFC1738]) offers a mechanism to refer to a resource, but not to a location within a resource. The Web community has adopted a convention called "fragment URLs" to refer to anchors within an HTML document. A fragment URL ends with "#" followed by an anchor identifier. For instance, here is a fragment URL pointing to an anchor named section_2:
http://somesite.com/html/top.html#section_2

Relative URLs
A relative URL (defined in [RFC1808]) doesn't contain any protocol or machine information, and its path generally refers to an HTML document on the same machine as the current document. Relative URLs may contain relative path components (".." means the parent location) and may be fragment URLs.

eAbyas Info Solutions

15

Relative URLs may be resolved to full URLs, for example when the user attempts to follow a link from one document to another. [RFC1808] defines the normative algorithm for resolving relative URLs. The following description is for convenience only. Briefly, a full URL is derived from a relative URL by attaching a "base" part to the relative URL. The base part is a URL that may come from any or all of the following sources:

HTTP transfer protocol header information (see [RFC2068]). Metadata (the META element) in the HEAD section of an HTML document. Explicit base path information (the BASE element) in the HEAD section of an HTML document, or the CODEBASE attribute of the APPLET element.

[RFC1808] specifies the precedence among multiple sources of base information. For the purposes of this explanation, the last piece of base information takes precedence over the others and HTTP headers are considered to occur earlier than the document HEAD. If no explicit base information accompanies the document, the base URL is that which designates the location of the current document. Given a base URL and a relative URL (that does not begin with a slash), a full URL is derived as follows:

If the base URL ends with a slash the full URL is derived by appending the relative URL to the base URL. For example, if the base URL is http://nosite.com/dir1/dir2/ and the relative URL is gee.html, the derived URL is http://nosite.com/dir1/dir2/gee.html. If the base URL doesn't end with a slash, the last piece of the base URL is considered a resource, so the full URL is derived by appending the relative URL to the parent of the base URL. For example, if the base URL is http://nosite.com/dir1/dir2 and the relative URL is gee.html, the derived URL is http://nosite.com/dir1/gee.html

URLs in HTML
In HTML, URLs play a role in these situations:

When referring to metadata describing a document (see the HEAD element). When citing a external reference (see the Q, BLOCKQUOTE, INS, and DEL elements). When including an object directly in a document (see the OBJECT, IMG, MAP, FRAME, and IFRAME elements).

eAbyas Info Solutions

16

When linking to another document or program (see the BASE, A, LINK, AREA, FORM, INPUT, SCRIPT, and APPLET elements).

In each case, authors may use a full URL, a fragment URL, or a relative URL. Please consult the section on anchors for more information about links and URLs.
MAILTO URLs

In addition to HTTP URLs, authors might want to include MAILTO URLs (see [RFC1738]) in their documents. MAILTO URLs cause email to be sent to some email address. For instance, the author might create a link that, when activated, causes the user agent to open a mail program with the destination address in the "To:" field. MAILTO URLs have the following syntax:
mailto:email-address

User agents may support MAILTO URL extensions that are not yet Internet standards (e.g., appending subject information to a URL with the syntax "?Subject=my%20subject" where any space characters are replaced by "%20").

HTML URL Encoding


INTRODUCTION TO URL ENCODING
URL Encoding Background URL Encoding is the process of converting string into valid URL format. Valid URL format means that the URL contains only what is termed "alpha | digit | safe | extra | escape" characters. URL encoding is normally performed to convert data passed via html forms, because such data may contain special character, such as "/", ".", "#", and so on, which could either: a) have special meanings; or b) is not a valid character for an URL; or c) could be altered during transfer. For instance, the "#" character needs to be encoded because it has a special meaning of that of an

eAbyas Info Solutions

17

html anchor. The <space> character also needs to be encoded because is not allowed on a valid URL format. Also, some characters, such as "~" might not transport properly across the internet. What Should be URL Encoded? As a rule of thumb, any non alphanumeric character should be URL encoded. This of course applies to characters that are to be interpreted as is (ie: is not intend to have special meanings) . In such cases, there's no harm in URL-Encoding the character, even if the character actually does not need to be URL-Encoded.

URL encoding is the practice of translating unprintable characters or characters with special meaning within URLs to a representation that is unambiguous and universally accepted by web browsers and servers. These characters include:

ASCII control characters - Unprintable characters typically used for output control. Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). A complete encoding table is given below. Non-ASCII control characters - These are characters beyond the ASCII character set of 128 characters. This range is part of the ISO-Latin character set and ncludes the entire "top half" of the ISO-Latin set 80-FF hex (128-255 decimal). A complete encoding table is given below. Reserved characters - These are special characters such as the dollar sign, ampersand, plus, common, forward slash, colon, semi-colon, equals sign, question mark, and "at" symbol. All of these can have different meanings inside a URL so need to be encoded. A complete encoding table is given below. Unsafe characters - These are space, quotation marks, less than symbol, greater than symbol, pound character, percent character, Left Curly Brace, Right Curly Brace , Pipe, Backslash, Caret, Tilde, Left Square Bracket , Right Square Bracket, Grave Accent. These character present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded. A complete encoding table is given below.

The encoding notation replaces the desired character with three characters: a percent sign and two hexadecimal digits whose correspond to the position of the character in the ASCII character set.

eAbyas Info Solutions

18

Example:
One of the most common special characters is the space. You can't type a space in a URL directly. A space position in the character set is 20 hexadecimal. So you can use %20 in place a space when passing your request to the server.
http://www.example.com/new%20pricing.html

This URL actually retrieves a document named new pricing.html from the www.example.com

ASCII control characters encoding


This includes the encoding for character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal)
Decimal Hex Value 0 1 2 3 4 5 6 00 01 02 03 04 05 06 Character URL Encode %00 %01 %02 %03 %04 %05 %06

eAbyas Info Solutions

19

7 8 9 10 11 12 13 14 15 16 17 18 19 20

07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 backspace tab linefeed

%07 %08 %09 %0a %0b %0c carriage return %0d %0e %0f %10 %11 %12 %13 %14

eAbyas Info Solutions

20

21 22 23 24 25 26 27 28 29 30 31 127

15 16 17 18 19 1a 1b 1c 1d 1e 1f 7f

%15 %16 %17 %18 %19 %1a %1b %1c %1d %1e %1f %7f

Non-ASCII control characters encoding


This includes the encoding for the entire "top half" of the ISO-Latin set 80-FF hex (128-255 decimal.)

eAbyas Info Solutions

21

Decimal Hex Value Character URL Encode 128 129 130 131 132 133 134 135 136 137 138 139 140 80 81 82 83 84 85 86 87 88 89 8a 8b 8c %80 %81 %82 %83 %84 %85 %86 %87 %88 %89 %8a %8b %8c

eAbyas Info Solutions

22

141 142 143 144 145 146 147 148 149 150 151 152 153 154

8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a

%8d %8e %8f %90 %91 %92 %93 %94 %95 %96 %97 %98 %99 %9a

eAbyas Info Solutions

23

155 156 157 158 159 160 161 162 163 164 165 166 167 168

9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8

%9b %9c %9d

%9e %9f %a0

%a1 %a2 %a3 %a4 %a5 %a6 %a7 %a8

eAbyas Info Solutions

24

169 170 171 172 173 174 175 176 177 178 179 180 181 182

a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6

%a9 %aa %ab %ac %ad

%ae %af %b0 %b1 %b2 %b3 %b4 %b5 %b6

eAbyas Info Solutions

25

183 184 185 186 187 188 189 190 191 192 193 194 195 196

b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4

%b7 %b8 %b9 %ba %bb %bc %bd %be %bf %c0 %c1 %c2 %c3 %c4

eAbyas Info Solutions

26

197 198 199 200 201 202 203 204 205 206 207 208 209 210

c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2

%c5 %v6 %c7 %c8 %c9 %ca %cb %cc %cd %ce %cf %d0 %d1 %d2

eAbyas Info Solutions

27

211 212 213 214 215 216 217 218 219 220 221 222 223 224

d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0

%d3 %d4 %d5 %d6 %d7 %d8 %d9 %da %db %dc %dd %de %df %e0

eAbyas Info Solutions

28

225 226 227 228 229 230 231 232 233 234 235 236 237 238

e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee

%e1 %e2 %e3 %e4 %e5 %e6 %e7 %e8 %e9 %ea %eb %ec %ed %ee

eAbyas Info Solutions

29

239 240 241 242 243 244 245 246 247 248 249 250 251 252

ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc

%ef %f0 %f1 %f2 %f3 %f4 %f5 %f6 %f7 %f8 %f9 %fa %fb %fc

eAbyas Info Solutions

30

253 254 255

fd fe ff

%fd %fe %ff

Reserved characters encoding


Following is the table to be used to encode reserved characters.
Decimal Hex Value Char URL Encode 36 38 43 44 47 58 59 61 24 26 2b 2c 2f 3a 3b 3d $ & + , / : ; = %24 %26 %2b %2c %2f %3a %3b %3d

eAbyas Info Solutions

31

63 64

3f 40

? @

%3f %40

Unsafe characters encoding


Following is the table to be used to encode unsafe characters.
Decimal Hex Value 32 34 60 62 35 37 123 125 124 20 22 3c 3e 23 25 7b 7d 7c Char URL Encode

space %20 " < > # % { } | %22 %3c %3e %23 %25 %7b %7d %7c

eAbyas Info Solutions

32

92 94 126 91 93 96

5c 5e 7e 5b 5d 60

\ ^ ~ [ ] `

%5c %5e %7e %5b %5d %60

HTML Script

Introduction to scripts
A client-side script is a program that may accompany an HTML document or be embedded directly in it. The program executes on the client's machine when the document loads, or at some other time such as when a link is activated. HTML's support for scripts is independent of the scripting language. Scripts offer authors a means to extend HTML documents in highly active and interactive ways. For example:

Scripts may be evaluated as a document loads to modify the contents of the document dynamically. Scripts may accompany a form to process input as it is entered. Designers may dynamically fill out parts of a form based on the values of other fields. They may also ensure that input data conforms to predetermined ranges of values, that fields are mutually consistent, etc. Scripts may be triggered by events that affect the document, such as loading, unloading,

eAbyas Info Solutions

33

element focus, mouse movement, etc. Scripts may be linked to form controls (e.g., buttons) to produce graphical user interface elements.

There are two types of scripts authors may attach to an HTML document:

Those that are executed one time when the document is loaded by the user agent. Scripts that appear within a SCRIPT element are executed when the document is loaded. For user agents that cannot or will not handle scripts, authors may include alternate content via the NOSCRIPT element. Those that are executed every time a specific event occurs. These scripts may be assigned to a number of elements via the intrinsic event attributes.

HTML Script Tags


Tag Description <script> Defines a client-side script <noscript> Defines an alternate content for users that do not support client-side scripts

The HTML script Element


The <script> tag is used to define a client-side script, such as a JavaScript. The script element either contains scripting statements or it points to an external script file through the src attribute. The required type attribute specifies the MIME type of the script. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content. The script below writes Hello World! to the HTML output:

eAbyas Info Solutions

34

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

The HTML noscript Element


The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesnt support client-side scripting. The noscript element can contain all the elements that you can find inside the body element of a normal HTML page. The content inside the noscript element will only be displayed if scripts are not supported, or are disabled in the users browser:

Example
<script type="text/javascript"> document.write("Hello World!") </script> <noscript>Sorry, your browser does not support JavaScript!</noscript>

Designing documents for user agents that support scripting


The following sections discuss issues that concern user agents that support scripting.

18.2.1 The SCRIPT element


<!ELEMENT SCRIPT - - %Script; <!ATTLIST SCRIPT charset %Charset; #IMPLIED type %ContentType; #REQUIRED src %URI; #IMPLIED defer (defer) #IMPLIED > -- script statements --> ----char encoding of linked resource -content type of script language -URI for an external script -UA may defer execution of script --

eAbyas Info Solutions

35

Start tag: required, End tag: required Attribute definitions


src = uri [CT] This attribute specifies the location of an external script. type = content-type [CI] This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute. language = cdata [CI] Deprecated. This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type. defer [CI] When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.

Attributes defined elsewhere

charset(character encodings)

The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document. The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script

eAbyas Info Solutions

36

via the URI. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the SCRIPT element. Scripts are evaluated by script engines that must be known to a user agent. The syntax of script data depends on the scripting language.

18.2.2 Specifying the scripting language


As HTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script. This may be done either through a default declaration or a local declaration.
The default scripting language

Authors should specify the default scripting language for all scripts in a document by including the following META declaration in the HEAD:
<META http-equiv="Content-Script-Type" content="type">

where "type" is a content type naming the scripting language. Examples of values include "text/tcl", "text/javascript", "text/vbscript". In the absence of a META declaration, the default can be set by a "Content-Script-Type" HTTP header.
Content-Script-Type: type

where "type" is again a content type naming the scripting language. User agents should determine the default scripting language for a document according to the following steps (highest to lowest priority):
1. If any META declarations specify the "Content-Script-Type", the last one in the character stream determines the default scripting language. 2. Otherwise, if any HTTP headers specify the "Content-Script-Type", the last one in the character stream determines the default scripting language.

eAbyas Info Solutions

37

Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect. User agents may still attempt to interpret incorrectly specified scripts but are not required to. Authoring tools should generate default scripting language information to help authors avoid creating incorrect documents.
Local declaration of a scripting language

The type attribute must be specified for each SCRIPT element instance in a document. The value of the type attribute for a SCRIPT element overrides the default scripting language for that element. In this example, we declare the default scripting language to be "text/tcl". We include one SCRIPT in the header, whose script is located in an external file and is in the scripting language "text/vbscript". We also include one SCRIPT in the body, which contains its own script written in "text/javascript".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>A document with SCRIPT</TITLE> <META http-equiv="Content-Script-Type" content="text/tcl"> <SCRIPT type="text/vbscript" src="http://someplace.com/progs/vbcalc"> </SCRIPT> </HEAD> <BODY> <SCRIPT type="text/javascript"> ...some JavaScript... </SCRIPT> </BODY> </HTML>

References to HTML elements from a script

Each scripting language has its own conventions for referring to HTML objects from within a script. This specification does not define a standard mechanism for referring to HTML objects. However, scripts should refer to an element according to its assigned name. Scripting engines should observe the following precedence rules when identifying an element: a name attribute takes precedence over an id if both are set. Otherwise, one or the other may be used.

eAbyas Info Solutions

38

18.2.3 Intrinsic events


Note. Authors of HTML documents are advised that changes are likely to occur in the realm of intrinsic events (e.g., how scripts are bound to events). Research in this realm is carried on by members of the W3C Document Object Model Working Group (see the W3C Web Site at http://www.w3.org/ for more information). Attribute definitions
onload = script [CT] The onload event occurs when the user agent finishes loading a window or all frames within a FRAMESET. This attribute may be used with BODY and FRAMESET elements. onunload = script [CT] The onunload event occurs when the user agent removes a document from a window or frame. This attribute may be used with BODY and FRAMESET elements. onclick = script [CT] The onclick event occurs when the pointing device button is clicked over an element. This attribute may be used with most elements. ondblclick = script [CT] The ondblclick event occurs when the pointing device button is double clicked over an element. This attribute may be used with most elements. onmousedown = script [CT] The onmousedown event occurs when the pointing device button is pressed over an element. This attribute may be used with most elements. onmouseup = script [CT] The onmouseup event occurs when the pointing device button is released over an element. This attribute may be used with most elements.

eAbyas Info Solutions

39

onmouseover = script [CT] The onmouseover event occurs when the pointing device is moved onto an element. This attribute may be used with most elements. onmousemove = script [CT] The onmousemove event occurs when the pointing device is moved while it is over an element. This attribute may be used with most elements. onmouseout = script [CT] The onmouseout event occurs when the pointing device is moved away from an element. This attribute may be used with most elements. onfocus = script [CT] The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation. This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON. onblur = script [CT] The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus. onkeypress = script [CT] The onkeypress event occurs when a key is pressed and released over an element. This attribute may be used with most elements. onkeydown = script [CT] The onkeydown event occurs when a key is pressed down over an element. This attribute may be used with most elements. onkeyup = script [CT] The onkeyup event occurs when a key is released over an element. This attribute may be used

eAbyas Info Solutions

40

with most elements. onsubmit = script [CT] The onsubmit event occurs when a form is submitted. It only applies to the FORM element. onreset = script [CT] The onreset event occurs when a form is reset. It only applies to the FORM element. onselect = script [CT] The onselect event occurs when a user selects some text in a text field. This attribute may be used with the INPUT and TEXTAREA elements. onchange = script [CT] The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.

It is possible to associate an action with a certain number of events that occur when a user interacts with a user agent. Each of the "intrinsic events" listed above takes a value that is a script. The script is executed whenever the event occurs for that element. The syntax of script data depends on the scripting language. Control elements such as INPUT, SELECT, BUTTON, TEXTAREA, and LABEL all respond to certain intrinsic events. When these elements do not appear within a form, they may be used to augment the graphical user interface of the document. For instance, authors may want to include press buttons in their documents that do not submit a form but still communicate with a server when they are activated. The following examples show some possible control and user interface behavior based on intrinsic events. In the following example, userName is a required text field. When a user attempts to leave the field, the onblur event calls a JavaScript function to confirm that userName has an acceptable value.

eAbyas Info Solutions

41

<INPUT NAME="userName" onblur="validUserName(this.value)">

Here is another JavaScript example:


<INPUT NAME="num" onchange="if (!checkNum(this.value, 1, 10)) {this.focus();this.select();} else {thanks()}" VALUE="0">

Here is a VBScript example of an event handler for a text field:


<INPUT name="edit1" size="50"> <SCRIPT type="text/vbscript"> Sub edit1_changed() If edit1.value = "abc" Then button1.enabled = True Else button1.enabled = False End If End Sub </SCRIPT>

Here is the same example using Tcl:


<INPUT name="edit1" size="50"> <SCRIPT type="text/tcl"> proc edit1_changed {} { if {[edit value] == abc} { button1 enable 1 } else { button1 enable 0 } } edit1 onChange edit1_changed </SCRIPT>

Here is a JavaScript example for event binding within a script. First, here's a simple click handler:
<BUTTON type="button" name="mybutton" value="10"> <SCRIPT type="text/javascript"> function my_onclick() { . . .

eAbyas Info Solutions

42

} document.form.mybutton.onclick = my_onclick </SCRIPT> </BUTTON>

Here's a more interesting window handler:


<SCRIPT type="text/javascript"> function my_onload() { . . . } var win = window.open("some/other/URI") if (win) win.onload = my_onload </SCRIPT>

In Tcl this looks like:


<SCRIPT type="text/tcl"> proc my_onload {} { . . . } set win [window open "some/other/URI"] if {$win != ""} { $win onload my_onload } </SCRIPT>

Note that "document.write" or equivalent statements in intrinsic event handlers create and write to a new document rather than modifying the current one.

Dynamic modification of documents


Scripts that are executed when a document is loaded may be able to modify the document's contents dynamically. The ability to do so depends on the scripting language itself (e.g., the "document.write" statement in the HTML object model supported by some vendors).

The dynamic modification of a document may be modeled as follows:


1. All SCRIPT elements are evaluated in order as the document is loaded. 2. All script constructs within a given SCRIPT element that generate SGML CDATA are evaluated.

eAbyas Info Solutions

43

Their combined generated text is inserted in the document in place of the SCRIPT element. 3. The generated CDATA is re-evaluated.

HTML documents are constrained to conform to the HTML DTD both before and after processing any SCRIPT elements. The following example illustrates how scripts may modify a document dynamically. The following script:
<TITLE>Test Document</TITLE> <SCRIPT type="text/javascript"> document.write("<p><b>Hello World!<\/b>") </SCRIPT>

Has the same effect as this HTML markup:


<TITLE>Test Document</TITLE> <P><B>Hello World!</B>

Designing documents for user agents that don't support scripting


The following sections discuss how authors may create documents that work for user agents that don't support scripting.

18.3.1 The NOSCRIPT element


<!ELEMENT NOSCRIPT - - (%block;)+ -- alternate content container for non script-based rendering --> <!ATTLIST NOSCRIPT %attrs; -- %coreattrs, %i18n, %events ->

Start tag: required, End tag: required


The NOSCRIPT element allows authors to provide alternate content when a script is not executed. The content of a NOSCRIPT element should only be rendered by a script-aware user agent in the following cases:

eAbyas Info Solutions

44

The user agent is configured not to evaluate scripts. The user agent doesn't support a scripting language invoked by a SCRIPT element earlier in the document.

User agents that do not support client-side scripts must render this element's contents. In the following example, a user agent that executes the SCRIPT will include some dynamically created data in the document. If the user agent doesn't support scripts, the user may still retrieve the data through a link.
<SCRIPT type="text/tcl"> ...some Tcl script to insert data... </SCRIPT> <NOSCRIPT> <P>Access the <A href="http://someplace.com/data">data.</A> </NOSCRIPT>

Hiding script data from user agents


User agents that don't recognize the SCRIPT element will likely render that element's contents as text. Some scripting engines, including those for languages JavaScript, VBScript, and Tcl allow the script statements to be enclosed in an SGML comment. User agents that don't recognize the SCRIPT element will thus ignore the comment while smart scripting engines will understand that the script in comments should be executed. Another solution to the problem is to keep scripts in external documents and refer to them with the src attribute. Commenting scripts in JavaScript The JavaScript engine allows the string "<!--" to occur at the start of a SCRIPT element, and ignores further characters until the end of the line. JavaScript interprets "//" as starting a comment extending to the end of the current line. This is needed to hide the string "-->" from the JavaScript parser.
<SCRIPT type="text/javascript"> <!-- to hide script contents from old browsers function square(i) { document.write("The call passed ", i ," to the function.","<BR>") return i * i }

eAbyas Info Solutions

45

document.write("The function returned ",square(5),".") // end hiding contents from old browsers --> </SCRIPT>

Commenting scripts in VBScript In VBScript, a single quote character causes the rest of the current line to be treated as a comment. It can therefore be used to hide the string "-->" from VBScript, for instance:
<SCRIPT type="text/vbscript"> <!-Sub foo() ... End Sub ' --> </SCRIPT>

Commenting scripts in TCL In Tcl, the "#" character comments out the rest of the line:
<SCRIPT type="text/tcl"> <!-- to hide script contents from old browsers proc square {i} { document write "The call passed $i to the function.<BR>" return [expr $i * $i] } document write "The function returned [square 5]." # end hiding contents from old browsers --> </SCRIPT>

HTML Entities
Some characters are reserved in HTML. It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags.

eAbyas Info Solutions

46

To actually display reserved characters, we must use character entities in the HTML source code. A character entity looks like this: &entity_name; OR &#entity_number; To display a less than sign we must write: &lt; or &#60;

Non-breaking Space
A common character entity used in HTML is the non-breaking space (&nbsp;). Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity.

HTML Useful Character Entities


Note: Entity names are case sensitive! Result Description non-breaking space < less than > greater than & ampersand cent pound yen euro section copyright Entity Name Entity Number &nbsp; &#160; &lt; &#60; &gt; &#62; &amp; &#38; &cent; &#162; &pound; &#163; &yen; &#165; &euro; &#8364; &sect; &#167; &copy; &#169;

eAbyas Info Solutions

47

registered trademark &reg; trademark &trade;

&#174; &#8482;

HTML Webserver
After HTML coding process is completed, the webpage needs to be published, to make it available for the audience. To enable this, it is necessary to save the webpage on a web server. After IIS or PWS installation, any PC can serve as a web server. IIS or PWS are web server components. IIS contains a set of services designed specifically for MS Windows. It is included into Win 2000, Win XP and Vista. It is quite easy to install and use this application. IIS includes Active Server Pages, which can be used for making interactive and dynamic web applications. Personal Web Server is designed for use with older versions of WindowsOS, such as Win 95, Win 98, and Win NT. It is recommended to use IIS, because it more up-to-date and secure.

Hosting your own Web site


Hosting your web site on your own server is always an option. Here are some points to consider:

Hardware Expenses
To run a "real" web site, you will have to buy some powerful server hardware. Don't expect that a low cost PC will do the job. You will also need a permanent (24 hours a day ) high-speed connection.

Software Expenses
Remember that server-licenses often are higher than client-licenses. Also note that serverlicenses might have limits on number of users.

Labor Expenses
Don't expect low labor expenses. You have to install your own hardware and software. You also

eAbyas Info Solutions

48

have to deal with bugs and viruses, and keep your server constantly running in an environment where "everything could happen".

Using an Internet Service Provider


Renting a server from an Internet Service Provider (ISP) is a common option. Most small companies store their web site on a server provided by an ISP. Here are some advantages:

Connection Speed
Most ISPs have very fast connections to the Internet.

Powerful Hardware
ISPs often have powerful web servers that can be shared by several companies. You can also expect them to have an effective load balancing, and necessary backup servers.

Security and Stability


ISPs are specialists on web hosting. Expect their servers to have more than 99% up time, the latest software patches, and the best virus protection.

Things to Consider with an ISP


24-hour support
Make sure your ISP offers 24-hours support. Don't put yourself in a situation where you cannot fix critical problems without having to wait until the next working day. Toll-free phone could be vital if you don't want to pay for long distance calls.

eAbyas Info Solutions

49

Daily Backup
Make sure your ISP runs a daily backup routine, otherwise you may lose some valuable data.

Traffic Volume
Study the ISP's traffic volume restrictions. Make sure that you don't have to pay a fortune for unexpected high traffic if your web site becomes popular.

Bandwidth or Content Restrictions


Study the ISP's bandwidth and content restrictions. If you plan to publish pictures or broadcast video or sound, make sure that you can.

E-mail Capabilities
Make sure your ISP supports the e-mail capabilities you need.

Database Access
If you plan to use data from databases on your web site, make sure your ISP supports the database access you need.

eAbyas Info Solutions

50

eAbyas Info Solutions

S-ar putea să vă placă și