JavaScript Popups

<head>
<script type="text/javascript">

function testPopup() {
window.open( "http://www.google.com/" )
}

</script>
</head>
<body>
<form>
<input type="button" onClick="testPopup()" value="Click">
</form>
</body>


OpenNewWindow =window.open('contact.html','help','toolbar=no,
location=0,directories=no,status=yes,menubar
=0,scrollbars=yes,resizable=yes,
width=300,height=350')





JavaScript Window.Open Arguments


When you open a window, you can set its URL, name, size, buttons, and other attributes, such as whether or not the window can be resized. The basic syntax of this method is


window.open(url, name, features, replace)


where

url is a URL that indicates the document to load into the window.

name is the name for the window (which is useful for referencing later on using the target attribute of HTML links).features is a comma-delimited string that lists the features of the window.

replace is an optional Boolean value (true or false) that indicates if the URL specified should replace the window’s contents or not. This would apply to a window that was already created.

An example of this method is

secondwindow = open("http://www.yahoo.com", "yahoo", "height=300,width=200,

 scrollbars=yes");



<a href="http://www.google.com" target="_blank">Go to Google</a>

Javascript Making a simple MouseOver

<a href="http://www.cit.cornell.edu"
onMouseOver="document.logo.src='family.gif ' ; "
onMouseOut ="document.logo.src='harry.gif ' ; " >
<img name="logo" src="harry.gif " border=0></a>


The onMouseOver and onMouseOut attributes are “Event Handlers” that tell the browser what
code to execute when the events occur. You can make it so that the mouseover affects another image on
the page by changing the name of the image accordingly in the event handler code.

We can use a MouseOver to animate a still image when the
mouse rolls over it. In your class files folder you have two images, logoscroll.gif and logostill.gif which
can be used to create this effect.

Javascript String Constructor

String is the built-in object corresponding to the primitive string data type. It contains a very large number of methods for string manipulation and examination, substring extraction, and even conversion of strings to marked-up HTML, though unfortunately not standards-oriented XHTML.

The String() constructor takes an optional argument that specifies its initial value:

var s = new String();

var headline = new String("Dewey Defeats Truman");


Because you can invoke String methods on primitive strings, programmers rarely create String objects in practice.

The only property of String is length, which indicates the number of characters in the string.

var s = "String fun in JavaScript";

var strlen = s.length;

// strlen is set to 24


The length property is automatically updated when the string changes and cannot be set by the programmer. In fact there is no way to manipulate a string directly. That is, String methods do not operate on their data “in place.” Any method that would change the value of the string, returns a string containing the result. If you want to change the value of the string, you must set the string equal to the result of the operation. For example, converting a string to uppercase with the toUpperCase() method would require the following syntax:

var s = "abc";

s = s.toUpperCase();

// s is now "ABC"
Invoking s.toUpperCase() without setting s equal to its result does not change the value of s. The following does not modify s:

var s = "abc";

s.toUpperCase();

// s is still "abc"
Other simple string manipulation methods such as toLowerCase() work in the same way; forgetting this fact is a common mistake made by new JavaScript programmers.

JavaScript String Split Function

split()

The split() method splits (for lack of a better word) a string up into substrings and returns them in an array. It accepts a string or regular expression argument containing the delimiter at which the string will be broken.

<script type="text/javascript">
var testString = "It is very nice script";

var testSplitResult = testString.split(" ");

for(i = 0; i < testSplitResult.length; i++){
    document.write("<br /> Element " + i + " = " + testSplitResult[i]);
}
</script>

JavaScript Redirect

<script type="text/javascript">

window.location = "http://www.yoursite.com/"

</script>

JavaScript System Dialogs alert(),confirm(),prompt()

The browser is capable of invoking system dialogs to display to the user through the alert(),
confirm(), and prompt() methods. These dialogs are not related to the web page being displayed
in the browser and do not contain HTML. Their appearance is determined by operating system and/
or browser settings rather than CSS. Additionally, each of these dialogs is synchronous and modal,
meaning code execution stops when a dialog is displayed, and resumes
after it has been dismissed.

The alert() method has been used throughout this book. It simply
accepts a string to display to the user. When alert() is called, a
system message box displays the specifi ed text to the user, followed by
a single OK button.

Alert dialogs are typically used when users must be made aware of something that they have no
control over, such as an error. A user’s only choice is to dismiss the dialog after reading the message.
The second type of dialog is invoked by calling confirm(). A confi rm dialog looks similar to an
alert dialog in that it displays a message to the user. The main difference between the two is the

To determine if the user clicked OK or Cancel, the confirm() method
returns a Boolean value: true if OK was clicked, or false if Cancel
was clicked or the dialog box was closed by clicking the X in the
corner. Typical usage of a confi rm dialog looks like this:

if (confirm(“Are you sure?”)) {
alert(“I’m so glad you’re sure! “);
} else {
alert(“I’m sorry to hear you’re not sure. “);
}

If the OK button is clicked, prompt() returns the value in the text box; if Cancel is clicked or the
dialog is otherwise closed without clicking OK, the function returns null. Here’s an example:

var result = prompt(“What is your name? “, “”);
if (result !== null) {
alert(“Welcome, “ + result);
}

JavaScript Variables

Variables store a value you can refer to later in the script. Variable names
can be nearly any valid identifi er. A JavaScript identifi er is a word that
contains only letters, numbers, $, and _, and that doesn’t start with a
number.
Variables are a great demonstration of how statements and expressions
can be combined. You use a variable declaration statement to create a
variable.

var myVariable;

If you already have a variable, you can use a variable assignment expression
to assign it a value.

myVariable = 42;
42
You can combine a variable declaration with an assignment expression.
var myVariable = 42;
You can also string together several variable declarations with commas.
Don’t forget the commas, though! Leaving off a comma can have the
unintended side effect of declaring a global variable when you don’t
mean to do that.var variable1 = 4,
variable2 = 8,
variable3 = 15;

JavaScript has a relatively small number of built-in data types, including
these common types:
var myNumber = 42;
var myString = "A string of text";
var myBoolean = true;
var myArray = [myNumber, myString, myBoolean];

JavaScript Alert

The JavaScript alert is a dialogue box that pops up and takes the focus away from the current window and forces the web browser to read the message.


1.
<form>
<input type="button" onclick=
"alert('Are you sure you want to call')"
value="See">
</form>


2.
function myFunc() {
alert("executing myFunc!");
return true;
}

3.

for (var i = 0; i < 10; i++) {
var link = document.createElement("a");
link.innerHTML = "Link " + i;
link.href = "#";
link.onclick = function() {
alert("This is link " + i);
return false;
};
document.body.appendChild(link);
}

Web Application with PHP


PHP embedded in HTML

<html>
<head><title>Example 1</title></head>
<body>
<?php
/* If it is April 1st, we show a quote */
if (date('md' == '0401')) {
echo 'A bookstore is one of the only pieces of evidence we have '.
'that people are still thinking. <i>Jerry Seinfeld</i>';
} else {
echo 'Good morning!';
}
?>
</body>
</html>

The line
<?php
begins the PHP section embedded into the HTML code; the
line
?>
ends the PHP section. Notice that the code uses echo
to send the output.
When the text is so simple, the echo
statements are acceptable.

Creating A Function In Javascript

The basic structure of a function looks like this:

function functionName() {
// the JavaScript you want to run
}

The keyword function lets the JavaScript interpreter know you’re creating a function—
it’s similar to how you use if to begin an if/else statement or var to create a variable.

function printToday()
{
var today = new Date();
document.write(today.toDateString());
}

The function’s name is printToday. It has just two lines of JavaScript code that retrieve
the current date, convert the date to a format we can understand

Javascript Do While Loops

There’s another, less common type of loop, known as a do/while loop. This type of
loop works nearly identically to a while loop. Its basic structure looks like this:

do {
// javascript to repeat
} while (condition) ;

do {
var luckyNumber = prompt('What is your lucky number?','');
luckyNumber = parseInt(luckyNumber, 10);
} while (isNaN(luckyNumber));

Save this file and preview it in a web browser. Try typing text and other nonnumeric
symbols in the prompt dialog box. That annoying dialog box continues
to appear until you actually type a number.

Javascript For Loops

JavaScript offers another type of loop, called a for loop, that’s a little more compact
(and a little more confusing). For loops are usually used for repeating a series of
steps a certain number of times, so they often involve some kind of counter variable,
a conditional test, and a way of changing the counter variable. In many cases,
a for loop can achieve the same thing as a while loop, with fewer lines of code. For
example.

for (var num=1; num<=100; num++) {
document.write('Number ' + num + '<br>');
}


var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday'];
for (var i=0; i<days.length; i++) {
document.write(days[i] + ', ');
}

Since for loops provide an easy way to repeat a series of steps a set number of times,
they work really well for working through the elements of an array. The while loop
in Figure 3-5, which writes each item in an array to the page, can be rewritten using
a for loop,

Javascript While Loops

A while loop repeats a chunk of code as long as a particular condition is true; in other
words, while the condition is true. The basic structure of a while loop is this:

while (condition) {
// javascript to repeat
}

The first line introduces the while statement. As with a conditional statement, you
place a condition between the set of parentheses that follow the keyword while.

Say you want to print the numbers 1 to 5 on a page. One possible way to do that is
like this:

document.write('Number 1 <br>');
document.write('Number 2 <br>');
document.write('Number 3 <br>');
document.write('Number 4 <br>');
document.write('Number 5 <br>');

Notice that each line of code is nearly identical—only the number changes from line
to line. In this situation, a loop provides a more efficient way to achieve the same goal:

var num = 1;
while (num <= 5) {
document.write('Number ' + num + '<br>');
num += 1;
}

Javascript Array

You can access the contents of a simple variable just by using the variable’s name.
For example, alert(lastName) opens an alert box with the value stored in the variable
lastName. However, because an array can hold more than one value, you can’t just
use its name alone to access the items it contains. A unique number, called an index,
indicates the position of each item in an array. To access a particular item in an array,
you use that item’s index number. For example, say you’ve created an array with
abbreviations for the days of the week, and want to open an alert box that displayed
the first item.

var days = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun'];
alert(days[0]);


Javascript Object Type


Objects are
created by using the new operator followed by the name of the object type to create. Developers
create their own objects by creating instances of the Object type and adding properties and/or
methods to it, as shown here:

var o = new Object();

Each Object instance has the following properties and methods:
constructor — The function that was used to create the object. In the previous example,
the constructor is the Object() function.

hasOwnProperty(propertyName) — Indicates if the given property exists on the object
instance (not on the prototype). The property name must be specifi ed as a string (for
example, o.hasOwnProperty(“name”)).

isPrototypeOf(object) — Determines if the object is a prototype of another object.

propertyIsEnumerable(propertyName) — Indicates if the given property can be
enumerated using the for-in statement (discussed later in this chapter). As with
hasOwnProperty(), the property name must be a string.

toLocaleString() — Returns a string representation of the object that is appropriate for
the locale of execution environment.

toString() — Returns a string representation of the object.

valueOf() — Returns a string, number, or Boolean equivalent of the object. It often
returns the same value as toString().

HTML5 Constraint Validation API

HTML5 introduces the ability for browsers to validate data in forms before submitting to the
server. This capability enables basic validation even when JavaScript is unavailable or fails to load.
The browser itself handles performing the validation based on rules in the code and then displays
appropriate error messages on its own (without needing additional JavaScript). Of course, this
functionality works only in browsers that support this part of HTML5, including Firefox 4+,
Safari 5+, Chrome, and Opera 10+.
Validation is applied to a form fi eld only under certain conditions. You can use HTML markup to
specify constraints on a particular fi eld that will result in the browser automatically performing
form validation.

Required Fields
The fi rst condition is when a form fi eld has a required attribute, as in this example:

<input type=”text” name=”username” required>

Any field marked as required must have a value in order for the form to be submitted. This
attribute applies to <input>, <textarea>, and <select> fi elds (Opera through version 11 doesn’t
support required on <select>). You can check to see if a form fi eld is required in JavaScript by
using the corresponding required property on the element:
var isUsernameRequired = document.forms[0].elements[“username”].required;
You can also test to see if the browser supports the required attribute using this code snippet:
var isRequiredSupported = “required” in document.createElement(“input”);
This code uses simple feature detection to determine if the property required exists on a newly
created <input> element.

Keep in mind that different browsers behave differently when a form fi eld is required. Firefox 4 and
Opera 11 prevent the form from submitting and pop up a help box beneath the fi eld, while Safari (as
of version 5) and Chrome (as of version 9) do nothing and don’t prevent the form from submitting.

Javascript Event Object

Properties

Different types of events have different properties, which you’ll learn
about later in the chapter. Here are a few properties common to all standard
Event objects:
■ type The type of the event, like “click,” “load,” or “keypress.”
■ target The element that originally dispatched the event. This may not
be the same as the element to which the event handler is attached.
■ currentTarget The element to which you attached the event handler.
In most cases, it is synonymous with the this keyword. If you change
the context of the event handler with call() or apply(), you can still
access the element with currentTarget.
■ eventPhase A number that indicates whether the event is currently
capturing (1), bubbling (3), or at the target element (2). Find out more
information in the “Event Bubbling and Capturing” section later in this
chapter.
■ timeStamp A number in seconds that represents the time at which the
event occurred.


<a id="link" href="http://www.google.com">Don't go to
Google</a>
var link = document.getElementById("link");
link.addEventListener("click", dontFollowLink, false);
function dontFollowLink(event) {
alert("Not going to " + this.href);
event.preventDefault();

}


In Internet Explorer, the Event object isn’t available as an argument
of the handler. Instead, it’s a property of window. To write crossbrowser
DOM Level 0 code, look for the Event object in both places.
function handler(event) {
event = event || window.event;
}

Javascript Cookies

Cookies are small strings that let you store data across page views and
sessions. These are some common uses of cookies:
1. Keeping track of whether the user has logged in to your site
2. Remembering that a user has visited a page before
3. Differentiating between fi rst-time visitors and repeat visitors
Cookies are also sent to the server with every page request. That’s how
the server knows whether the user is logged in. Because cookies add data
to the request and therefore increase the size of the request, cookie data
is limited to 4KB.
The window.document object has a funny little property called cookie.
You can use that object to read and set cookie data.
Setting Cookies
To set a cookie, just assign the name and value to document.cookie
in the following format:
document.cookie = "name=value";
You can set only one cookie at a time, but assigning another value to
document.cookie doesn’t overwrite the previous cookies, unless one of
them shares the same name. You can continue to assign name/value pairs
to document.cookie until you hit the 4KB limit enforced by the browser.
// Adding another cookie
document.cookie = "anotherName=anotherValue";
You should always pass the value part of the string through
encodeURIComponent() to make sure it doesn’t contain any illegal
characters such as spaces, commas, and semicolons.
var cookieValue = "encoded value";
document.cookie = "thirdCookie=" +
encodeURIComponent(cookieValue);
You can also set the following optional parameters that affect the



// This secure cookie will last a year
document.cookie = "name=value;max-age=" + (60*60*24*365) +
";secure;";

You’ll have to use your string manipulation skills to extract a single
cookie’s value from this string. Regular expressions come in handy here.

function getCookie(name) {
// Get each individual cookie by splitting
// on semicolons and possible spaces
var cookies = document.cookie.split(/;\s*/);
// Make a regular expression to match the name
// and value in a subpattern
var pattern = new RegExp("\\b" + name + "=(.*)");
// Check each cookie until you fi nd a match
for (var i = 0, l = cookies.length; i < l; i++) {
var match = cookies[i].match(pattern);
if (match) {
return decodeURIComponent(match[1]);
}
}
}

Javascript forEach

Looping over arrays using functions is increasingly common, especially in
certain libraries. Modern browsers support the forEach() method, but
you can also build your own.
function arrayForEach(array, loopFunc) {
// If the browser support forEach, use it because
// it will be faster
if ("forEach" in array) {
return array.forEach(loopFunc);

// Otherwise, loop over the array and pass in
// the array values to the loop function
} else {
for (var i = 0, l = array.length; i < l; i++) {
loopFunc(array[i], i, array);
}
return array;
}
}
function doSomeMath(num) {
console.log(num * 10 - 5);
}
arrayForEach([1,2,3], doSomeMath);



5
15
25

Javascript Creating Arrays

The best way to create a new array is with the array literal syntax ([]),
but the array constructor function is available too. If you pass a single
number value to the constructor function, you get an array fi lled with
that many undefi ned values.
var myArray = [];
var myFilledArray = new Array(4);
myFilledArray;
[undefi ned, undefi ned, undefi ned, undefi ned]
Properties
Like strings, arrays have one built-in property: length. This property is
equal to the number greater than the last index in the array. This is true
even if you skip some indices.
["a", 1, true, null].length;
4
var myArray = [];
myArray.length;
0
myArray[99] = 1;
1
myArray.length;
100
The new length of myArray is 100 even though it contains only one value
at index 99. All the other values are undefined.

JavaScript String Length

The length  returns the number of characters that are in a string, using
an integer.


<script type="text/javascript">
var testString = "11111";
var length = testString.length;
document.write("The string length is: " + length);

</script>



output:-

The string length is: 5

Comparing strings in JavaScript


<script type="text/javascript">
var username = "test";
if(username == "test")
    document.write("Welcome");
else
    document.write("Access Denied!");
document.write("<br /><br />Try again?<br /><br />");


</script>

While '14' == 14 is true (because by converting either the left side
value to a number or converting the right side value to a text string
will result in both being the same) '123' === 123 is false since one
value is a text string and the other is a number.

The === operator does the same thing with one minor difference. This
operator does not convert data from one type to another.

JavaScript String indexOf

var p = navigator.platform;
system.win = p.indexOf(“Win”) == 0;
system.mac = p.indexOf(“Mac”) == 0;
system.x11 = (p.indexOf(“X11”) == 0) || (p.indexOf(“Linux”) == 0);


This code uses the indexOf() method to look at the beginning of the platform string. To detect
Windows, the platform-detection code simply looks for the string “Win” at the beginning of the
platform string (covers both “Win32” and “Win64”). Testing for a Mac platform is done in the same
way to accommodate both “MacPPC” and “MacIntel”. The test for Unix looks for both “X11” and
“Linux” at the beginning of the platform string to future-proof this code against other variants.

<script type="text/javascript">
var mURL = "http://www.google.com/";
var mPosition = mURL.indexOf("www");

document.write("The position of www  =  " + mPosition); 
</script>

Why Use Sitemaps?

It is important to use Sitemaps because they help your visitors quickly get to the information
they need, and they help web spiders find your site’s links.
There is no universal Sitemap rule that you can apply to every site. Understanding
different Sitemap options should help you identify the right type for each situation. The
following subsections discuss some of the reasons for using Sitemaps.

Crawl augmentation
Although web spiders are continuously improving, they are far from perfect. Search
engines have no problems admitting this.

Poor linking site structure
Not all sites are created equal. Sites with poor linking structures tend to index poorly.
Orphan pages, deep links, and search engine traps are culprits of poor site indexing.
The use of Sitemaps can alleviate these situations, at least temporarily, to give you
enough time to fix the root of the problem.

Crawling frequency
One of the biggest benefits of using Sitemaps is in timely crawls or recrawls of your site
(or just specific pages). XML Sitemap documents let you tell crawlers how often they
should read each page.
Sites using Sitemaps tend to be crawled faster on Yahoo! and Google. It takes Google
and Yahoo! minutes to respond to Sitemap submissions or resubmissions. This can be
very helpful for news sites, e-commerce sites, blogs, and any other sites that are constantly
updating or adding new content.

AdSense Earnings

The Google ads you are able to display on your content pages can be either cost-per-click
(CPC) or cost-per-1000-impressions (CPM) ads, while AdSense for search results pages
show exclusively CPC ads. This means that advertisers pay either when users click on
ads, or when the advertiser’s ad is shown on your site. You’ll receive a portion of the
amount paid for either activity on your website. Although we don’t disclose the exact
revenue share, our goal is to enable publishers to make as much or more than they could
with other advertising networks.

Typically, Google sends checks about one month behind if your earnings pass Google’s
payment threshold ($10 in the United States). You are responsible for paying any taxes
as required in your country. Let’s look at example earnings you can make with AdSense.
Suppose you have a site that shows 1,000 AdSense impressions per day. Assuming that
your CTR is at 1% and that the average click worth is $0.10, we get the following:
Daily AdSense Earnings =
1000 (impressions) × 0.01 (CTR) × 0.10 (click worth)
= $1

So, if you have a busy site, you can do the math and see what you can earn. It sounds
pretty simple, but to make it work you need to put in the time to create good content.
A lot depends on your visitor levels as well as how you integrate AdSense within your
site(s).

Competitor Research and Analysis

Competitor research and analysis may seem like a copycat activity, but it is not (at least
not entirely). It is about understanding what your competitors are doing. It is about
examining their keyword and linking strategies while realizing their current strengths
and weaknesses. The bottom line is that you are trying to understand what is making
your competitors rank.
This activity may comprise elements of emulation, but what you are really trying to do
is be better than your competition. Being better (in a general sense) means providing a
site with more value and better perception. In an SEO sense, it means understanding
all the things that make your competitors rank.
When learning about your competition, it is good to examine their past and present
activities, as well as implement ways to track their future activities. Although many
tools are available for you to use to learn about your competition, for most of your work
you can get by with the free tools that are available. This chapter emphasizes the free
tools and research that you can use in your work.

Finding Your Competition
Before you can analyze your competitors, you need to know who your competitors are.
How do you find your biggest competitors? One way to do this is to find sites that rank
for your targeted keywords. The sites that sell or provide products and services similar
to yours are your competitors.
There is a catch if you’re relying only on keywords, though. How do you know whether
you are targeting the right keywords? What if you miss important keywords? You may
be starting off in the wrong direction. This makes it all the more important to do your
keyword research properly. No tool or activity will ever be perfect. You have to start
somewhere.

Link Building

There are countless opportunities for link building. Everything starts on your site. Your
site should make it easy and intuitive for anyone wanting to link to it. To increase your
chances of people linking to your site, you need to provide something of value.
Basic Elements
The following subsections talk about the rudimentary elements that all sites need to
consider.
Take out the guesswork
Take out the guesswork for your web visitors by providing the HTML code fragment(s)
for people to link to your site. Create “Link to Us” and “Tell a Friend” links. Most CMS
software includes prebuilt forms for handling these simple concepts.

Run a daily, weekly, or monthly email newsletter
Running your own newsletter provides several benefits. First, you get to remind your
existing visitors of your new offerings, whether it is content, products, or services. Plus,
the recipients of your newsletter are likely to forward it to people they know if they find
your newsletter interesting.

Provide registered services
Many sites offer free and members-only content. This model offers several benefits. If
your free content is already great, many of your visitors will also be interested in your
members-only content. The idea is that the content that is provided to members only
is of even greater quality than the public content. Many sites charge for members-only
content. Providing registered services helps you build up the email lists that you can

JavaScript getElementById

getElementById() is a method of document object, it gets the tag element with the value "id" in its ID attribute.

To reference in a JS script to a HTML tag through its ID, use the following syntax:

    document.getElementById("id")

So even though the Internet Explorer JavaScript engine uses a mark-and-sweep
implementation, any COM objects that are accessed in JavaScript still use reference counting,
meaning circular references are still a problem when COM objects are involved. The following
simple example demonstrates a circular reference with a COM object:

var element = document.getElementById(“some_element”);
var myObject = new Object();
myObject.element = element;
element.someObject = myObject;

This example sets up a circular reference between a DOM element (element) and a native JavaScript
object (myObject). The myObject variable has a property called element that points to element,
and the element variable has a property called someObject that points back to myObject. Because
of this circular reference, the memory for the DOM element will never be reclaimed even if it is
removed from the page.

<script type="text/javascript">
function testEmpty(){
 var myTextField = document.getElementById('myTxt');
 if(myTxtField.value != "")
  alert("entered: " + myTxtField.value)
 else
  alert("please enter some text?")  
}
</script>
<input type='text' id='myTxt' />
<input type='button' onclick='testEmpty()' value='Checked' />

The argument that getElementById requires is the id of the HTML element you wish to utilize.

JavaScript Objects

Each Object instance has the following properties and methods:
constructor — The function that was used to create the object. In the previous example,
the constructor is the Object() function.

hasOwnProperty(propertyName) — Indicates if the given property exists on the object
instance (not on the prototype). The property name must be specifi ed as a string (for
example, dataObj.hasOwnProperty(“name”)).

isPrototypeOf(object) — Determines if the object is a prototype of another object.

propertyIsEnumerable(propertyName) — Indicates if the given property can be
enumerated using the for-in statement . As with
hasOwnProperty(), the property name must be a string.

toLocaleString() — Returns a string representation of the object that is appropriate for
the locale of execution environment.

toString() — Returns a string representation of the object.

valueOf() — Returns a string, number, or Boolean equivalent of the object. It often
returns the same value as toString().


A new instance of an object:

dataObj=new Object();

dataObj.firstname="Jonti";
dataObj.lastname="Leff";
dataObj.age=40;
dataObj.eyecolor="red";


JavaScript and HTML DOM

WORKING WITH THE DOM

In many cases, working with the DOM is fairly straightforward, making it easy to re-create with
JavaScript what normally would be created using HTML code.


 
Dynamic Scripts
The <script> element is used to insert JavaScript code into the page, either using by the src attribute
to include an external fi le or by including text inside the element itself. Dynamic scripts are those
that don’t exist when the page is loaded but are included later by using the DOM. As with the
HTML element, there are two ways to do this: pulling in an external fi le or inserting text directly.
Dynamically loading an external JavaScript fi le works as you would expect. Consider the following
<script> element:

<script type=”text/javascript” src=”client.js”></script>
This <script> element includes the text for the Chapter 9 client-detection script. The DOM code to
create this node is as follows:
var script = document.createElement(“script”);
script.type = “text/javascript”;
script.src = “client.js”;
document.body.appendChild(script);

JavaScript values, variables

If you try to declare a variable that already exists, JavaScript will treat it as a simple assignment statement and assign any new value in the declaration statement to the variable. If the duplicate declaration has no assignment, then nothing happens. If you try to assign a value to a non-existent variable, JavaScript will create the variable for you.

<script type="text/javascript">
//Commented lines starting with the double


//First we will declare a few variables
//and assign values to them


myTxt = "Do IT";
mynum =13;
//Note that myTxt is a string and mynum is numeric.

//Next we will display these to the user.

document.write(myTxt);

//To concatenate strings in JavaScript, use the '+' operator 
document.write("My favourite number is "+ mynum);
</script>

Include Inline JavaScript code

To include inline JavaScript code, place JavaScript code inside the <script> element directly, as
follows:
<script type=”text/javascript”>
function sayHi(){
alert(“Hi!”);
}
</script>

When using inline JavaScript code, keep in mind that you cannot have the string “</script>” anywhere
in your code. For example, the following code causes an error when loaded into a browser:
<script type=”text/javascript”>
function sayScript(){
alert(“</script>”);
}
</script>

Because of the way that inline scripts are parsed, the browser sees the string “</script>” as if it
were the closing </script> tag. This problem can be avoided easily by escaping the “/” character,
as in this example:
<script type=”text/javascript”>
function sayScript(){
alert(“<\/script>”);
}
</script>

What Is JavaScript

What Is JavaScript? — Explains the origins of JavaScript: where it came from, how it
evolved, and what it is today. Concepts introduced include the relationship between
JavaScript and ECMAScript, the Document Object Model (DOM), and the Browser
Object Model (BOM). A discussion of the relevant standards from the European Computer
Manufacturer’s Association (ECMA) and the World Wide Web Consortium (W3C) is also
included.

Considered the JavaScript expert by many people in the development community, author Douglas Crockford identifies the abundance of good ideas that make JavaScript an outstanding object-oriented programming language-ideas such as functions, loose typing, dynamic objects, and an expressive object literal notation. Unfortunately, these good ideas are mixed in with bad and downright awful ideas, like a programming model based on global variables.

Robots Meta Tag

Not everyone has access to their web server, but they still want to have control over how crawlers
behave on their web site. If you’re one of those, you can still control the crawlers that come to your
site. Instead of using the robots.txt file, you use a robots meta tag to make your preferences known
to the crawlers.

The robots meta tag is a small piece of HTML code that is inserted into the <HEAD> tag of your
web site and it works generally in the same manner that the robots.txt file does. You include your
instructions for crawlers inside the tags. The following example shows you how your robots meta

tag might look:
<html>
<head>
<meta name=”robots” content=”noindex, nofollow”>
<meta name=”description” content=”page description.”>
<title>
Web Site Title
</title>
</head>
<body>

This bit of HTML tells crawlers not to index the content on the site and not to follow the links on
the site. Of course, that might not be exactly what you had in mind. You can also use several other
robots meta tags for combinations of following, not following, indexing, and not indexing:
<meta name=”robots” content=”index,follow”>
<meta name=”robots” content=”noindex,follow”>

Key Factors Effecting Link Quality

According to SEO convention and the information gleaned from the Google patents, there
are a number of factors affecting the quality of your inbound links.

Link Density
Links from pages with fewer outbound links have more influence than from pages where
there are huge numbers of links – see FFAs. Additional outbound links dilute the value of
existing links on a page. My suggestion is to accept links from pages with no more than
10 to 12 links. Avoid pages with 20+ external links.

Site and Page Relevance
A link from a site and page carrying similar content would carry more influence than
from a site without the similar content.

Google Page Rank
For Google ranking purposes a link from a high Page Rank site has even greater
influence. A link from a PR 6+ site is extremely valuable. At the other extreme, I suggest
you are prudent when exchanging links with sites of a PR of zero. The PR0 category
contains a number of banned sites.

Anchor Text
Anchor text is the text that contains or sits alongside a link. This text provides additional
relevance to the quality of a link. Anchor text is written in HTML. On-screen part of the
text shows up as highlighted (usually coloured) or underlined type and part in normal
type. The anchor text for your site could be written in HTML code as follows:
<a href="http://www.yoursite.com"> Your Site Title </a> - A short description of what
you do. <BR>


Link Age
A long established link is deemed by Google to have more value than a recent link. A
rapid build up in links may also be deemed spam. However Google apparently makes an
allowance for a rapid build-up of links generated by news stories.

How to Optimise Your Site

Search engine optimisation is a marketing discipline. It is not a stand alone function.
Before any specific optimisation activity is undertaken it is essential that two areas are
non-search areas are appraised:
Understanding your Organisation’s Online Business Strategy
Good SEO requires a through understanding of your organisation’s overall business
strategy. How does search fit in with activities such as advertising, e-mail and direct
marketing? Is there a marketing plan? What does it say about objectives, strategy and
budgets? What is the overall direction of the business and what can search contribute?

Researching your Market Category, Customers and Competitors
Good SEO also requires a thorough understanding of the market category within which
the search project and web site will compete. What is the category size and how is it
developing. What other channels to market are there? What information is available
regarding their behaviour and attitude of customers? What role in the buying process is
played by the search marketing? Who are current and likely competitors? Once the above
is fully grasped you can proceed to the first real activity of SEO; Keyword selection.

Keyword Selection - Factors
Keyword selection is the first search specific discipline. Having explained that spiders
read and index text, we find that some text is more important than others. That text is
keywords. Valuable keywords are the words or phrases that prospective customers use
when searching in your market category. Keyword selection is therefore crucial and has
implications for so much else within search. I have drawn up a list of factors that should
be taken into account when selecting keywords.
Category Priorities
The first thing to remember is that the number of keywords you can use on any one site
or page has a finite limit. A general recommendation is that there is an overall limit of 20

Table basics in HTML

It’s reasonably straightforward to create a simple table when hand-coding markup. The
bare essentials of a single table is an opening <table> tag, followed by at least one table
row (a <tr>), followed by at least one table cell (a <td>, meaning “table data”). Here’s an
example:
<table>
<tr>
<td>Some data</td>
</tr>
</table>

That’s about as minimalist as you can get when it comes to creating tables, but you’re
unlikely to create a table with only one item of data, so let’s make things a touch more
interesting. The following markup is for a two-column table with four rows of data (the
presentational border attribute is just here as a visual aid to better distinguish the layout
of the table, and its effect should be replicated with CSS in a production environment):
<table border="1">
<tr>
<td>Name</td>
<td>Place of residence</td>
</tr>
<tr>
<td>Paul Haine</td>
<td>Oxford</td>
</tr>
<tr>
<td>Vikki Roberts</td>
<td>Bracknell</td>
</tr>
<tr>
<td>Leon Boardman</td>
<td>London</td>
</tr>
<tr>
<td>Emma Sax</td>
<td>Peaslake</td>
</tr>
</table>

Anatomy of an XHTML document

Finally, let’s look at how a strict XHTML 1.0 document is laid out:
<!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">
<head>
<title>Our title</title>
</head>
<body>
<p>Our content</p>
</body>
</html>
Let’s now go through this markup one line at a time.
Doctype declaration
First we see a doctype declaration. A doctype declaration provides an indication as to
what Document Type Definition (DTD) you’re going to be writing your markup to. A
DTD is basically a page detailing the rules and grammar of the markup. It can look a little
daunting, but let’s break it down and examine each piece. The doctype starts off like this:
<!DOCTYPE
Nothing much more to say here; this is just how a doctype begins. The root element of the
document that will appear after the doctype declaration—the <html> element—needs to
be specified immediately after the opening of the declaration:
<!DOCTYPE html
Note that we can use html or HTML, depending on the version of (X)HTML we’re writing to
and how we’re writing it. For all XHTML doctypes, the root element should be in lowercase,
but for HTML doctypes the root element may be uppercase if the rest of your tags
are written so.
Following that, we have the word PUBLIC:
<!DOCTYPE html PUBLIC
This indicates that the DTD we’re about to reference is publicly available. If the DTD was
private, then we would use SYSTEM instead (as in “a system resource,” probably a locally
held resource somewhere on your network).
Next we have the Formal Public Identifier (FPI), which describes details about both the DTD
and the organization behind the DTD.

XHTML vs. HTML

The question of whether to use XHTML or HTML will often not even come up in an average
web project; most web designers these days will naturally gravitate toward XHTML, as
it is perceived as being new, advanced, and the “X” makes it sound cool. The truth is,
XHTML isn’t as different from HTML as people think, and the purpose of this section of the
chapter is to discuss exactly how XHTML differs from earlier versions of HTML, debunk
some myths and misconceptions about XHTML and HTML, examine the issues behind
MIME types, and cover when it is (and isn’t) appropriate to use XHTML over HTML.

Differences between XHTML and HTML

There are several rules that apply to XHTML that do not apply to HTML. These are fairly
straightforward and you may know some (or all) of them already, but to reiterate:

The <html>, <head>, and <body> tags are all required in XHTML.

The <html> tag must have an xmlns attribute with a value of http://www.w3.org/
1999/xhtml.

All elements must be closed. I touched upon this earlier, but just remember that an
opening tag must have either an equal closing tag (if it’s a container tag) or a selfclosing
space-plus-slash.

All tags must be written in lowercase.

All attribute values must be quoted with either single quotes or double quotes.
Thus, class=page is invalid but class="page" and class='page' are both fine.

All attributes must have values. Some attributes, such as the selected attribute
used with the <option> tag, could be written in a shortened form in HTML—that is,
<option selected>data</option> would be valid. In XHTML, however, you must
write <option selected="selected">data</option>.

Ampersands should be encoded. That is, you should write &amp; instead of just &.
This is true wherever the ampersand is: in your content or in a URL.

id and class attributes

The id attribute is used to identify elements and mark up specific functional areas of a
website, and the class attribute is used to classify one or more elements. These important
attributes help you target elements when it comes to styling or scripting. I refer to both of
these attributes throughout the book, but for now all you need to know is that a specific
id attribute value can be used just once per page, whereas a class attribute value can be
used multiple times (the attributes themselves can be used multiple times per page). For

example, say you begin a document with this:
<body id="homepage">

You would then not be able to use an id attribute value of homepage anywhere else on the
same page. However, if you do this:
<body class="homepage">

then you are free to use the class attribute value of homepage as many times as you like
throughout the same page, but bear in mind that it still applies the same CSS, no matter
what tag you apply it to.

<div id="rightColumn">
<strong class="redText">
<p class="big">

Divs and spans

Divs and spans are two tags that, when used well, can help give your page a logical structure
and some extra hooks to apply any CSS or DOM scripting that you might need later. When
used badly, they can litter your document unnecessarily and make your markup, styling, and
scripting needlessly complicated.


<div id="header">
...
</div>
<div id="mainContent">
...
</div>
<div id="secondaryContent">
...
</div>
<div id="footer">
...
</div>

A span is used for marking out sections within a block element and sometimes inside
another inline element. It is an inline element, just the same as <em>, <strong>, or <a>,
except without any semantic meaning—it is simply a generic container. It can itself contain
further inline elements, including more spans. For example, say you wish to color the first
two words of a paragraph red, keeping the rest of the paragraph black. You can use a
<span> for this:
<p><span class="leadingWords">The first</span> two words of this å
paragraph can now be styled differently.</p>
A span cannot contain a block element—that is, you cannot place a <div> within a <span>
and expect it to work the way you want.

CSS and Canvas HTML5

As with most HTML elements, CSS can be applied to the canvas element itself to add borders, padding,
margins, etc. Additionally, some CSS values are inherited by the contents of the canvas; fonts are a good
example, as fonts drawn into a canvas default to the settings of the canvas element itself.
Furthermore, properties set on the context used in canvas operations follow the syntax you may
already be familiar with from CSS. Colors and fonts, for example, use the same notation on the context
that they use throughout any HTML or CSS document.
Browser Support for HTML5 Canvas
With the arrival of Internet Explorer 9, all browser vendors now provide support for HTML5 Canvas, and
it is already in the hands of a majority of users. This is a major milestone in web development, allowing
2D drawing to thrive on the modern Web.
In spite of the dwindling market share of previous versions of Internet Explorer, it is still a good idea
to first test whether HTML5 Canvas is supported before you use the APIs. The section “Checking for
Browser Support” later in this chapter will show you how you can programmatically check for browser
support.

Overview of HTML5 Canvas

When you use a canvas element in your web page, it creates a rectangular area on the page. By default,
this rectangular area is 300 pixels wide and 150 pixels high, but you can specify the exact size and set
other attributes for your canvas element.  A Basic Canvas Element
<canvas></canvas>
Once you have added a canvas element to your page, you can use JavaScript to manipulate it any
way you want. You can add graphics, lines, and text to it; you can draw on it; and you can even add
advanced animations to it.
The Canvas API supports the same two-dimensional drawing operations that most modern
operating systems and frameworks support. If you have ever programmed two-dimensional graphics in
recent years, you will probably feel right at home with the Canvas API because it is designed to be similar
to existing systems. If you haven’t, you’re about to discover how much more powerful a rendering
system can be than the previous images and CSS tricks developers have used for years to create web
graphics.
To programmatically use a canvas, you have to first get its context. You can then perform actions on
the context and finally apply those actions to the context. You can think of making canvas modifications
as similar to database transactions: you start a transaction, perform certain actions, and then commit
the transaction.

Using the Selectors API HTML5

getElementById() -Returns the element with the specified id attribute value
<div id="foo">
getElementById("foo");

getElementsByName() -Returns all elements whose name
attribute has the specified value
<input type="text" name="foo">
getElementsByName("foo");

getElementsByTagName() Return all elements whose tag name
matches the specified value
<input type="text">
getElementsByTagName("input");

With the new Selectors API, there are now more precise ways to specify which elements you would
like to retrieve without resorting to looping and iterating through a document using standard DOM. The
Selectors API exposes the same selector rules present in CSS as a means to find one or more elements in
the page. For example, CSS already has handy rules for selecting elements based on their nesting,
sibling, and child patterns.

CSS File for the HTML5 Page

body {
background-color:#CCCCCC;
font-family:Geneva,Arial,Helvetica,sans-serif;
margin: 0px auto;
max-width:900px;
border:solid;
border-color:#FFFFFF;
}
header {
background-color: #F47D31;
display:block;
color:#FFFFFF;
text-align:center;
13
}
header h2 {
margin: 0px;
}
h1 {
font-size: 72px;
margin: 0px;
}
h2 {
font-size: 24px;
margin: 0px;
text-align:center;
color: #F47D31;
}
h3 {
font-size: 18px;
margin: 0px;
text-align:center;
color: #F47D31;
}
h4 {
color: #F47D31;
background-color: #fff;
-webkit-box-shadow: 2px 2px 20px #888;
-webkit-transform: rotate(-45deg);
-moz-box-shadow: 2px 2px 20px #888;
-moz-transform: rotate(-45deg);
position: absolute;
padding: 0px 150px;
top: 50px;
left: -120px;
text-align:center;
}
One last thing to keep in mind is that browsers may seem to render things as if they actually
understand these new elements. The truth is, however, that these elements could have been renamed
foo and bar and then styled, and they would have been rendered the same way (but of course, they
would not have any benefits in search engine optimization). The one exception to this is Internet
Explorer, which requires that elements be part of the DOM. So, if you want to see these elements in IE,
you must programmatically insert them into the DOM and display them as block elements.

Submitting to directories

By now you’ve figured out that directories work differently from search engines. You must complete
the submission process to have your site included in most directories. But even when you’re submitting
information about your site, there’s an art to doing it.
How you list your site can mean the difference between the site being included in the directory or
not. Before you even begin to create your listing, it’s usually a good idea to navigate through the
directory that you’re submitting to. Look at other listings and make note of what works in them.
Keywords are of little importance when you’re creating your directory listing. Instead, what will make
the difference is the content on your web site. So if you’re faced with listing in a directory that’s strict
about reviewing sites before they are listed, make sure you have fresh content on your site. And it’s
also a good practice to keep that content fresh by updating it regularly.
Links can also be important when your site is being reviewed for inclusion in a directory, so be sure
you keep your links updated. Broken links can be detrimental to your site, and links that lead to
unrelated pages won’t reflect well either.
Other elements of your listing that editors evaluate for include:
1. Appropriate categorization
2. Accurate titles and descriptions
3.Title and descriptions relevant to the subject of the web site
4.Domain names that match site titles
5.Secure ordering capabilities on e-commerce sites
6.Contact information that’s easily accessible
7.Links to privacy policies, return policies, and product or service guarantees
8.Working and appropriate links to other sites and resources
9.Images that display properly in the most common browser formats
10.JavaScript that’s free of errors

Yahoo! Search Marketing

Another type of search engine is the directory search engine. Directories don’t display search results
based on keywords; instead they display results by category and subcategory. Web sites are usually
categorized by the site, not by pages on the site. What this means is that your overall listing in directory
search results will depend largely on either paid placement or on correctly categorizing your site
as tightly as possible.
Yahoo! Search Marketing is a PPC program that’s similar to AdWords, but there’s one big difference.
Yahoo! is a very commercial search engine, which means that many of the search results are
paid placement ads or are web sites that have been added by the web-site owner. Editors usually
review and approve submitted listings before they are shown in search results.
Yahoo! is also a portal that contains many different services, such as instant messaging, e-mail, maps,
and much more (Google is structured in a similar manner). Being a portal means that Yahoo! has
many loyal users who are likely to see your ads once you begin a PPC campaign with Yahoo! Search
Marketing.
When you sign up with Yahoo! Search Marketing, you have two options for the type of account you’d
like to have. These options are different from Google, because you can have a free PPC plan that you
use, create, and maintain on your own, or you can choose to have a Yahoo! specialist help you create
your campaign. If you decide to use a Yahoo! specialist, there’s a one-time $199 set-up fee.
As with Google, there’s no reason you should pay to begin your PPC advertising with Yahoo! Search
Marketing.

Google AdWords

Google AdWords is the PPC company you’ve probably heard the most about. AdWords is one of
the top search engine marketing programs, and Google is one of the biggest providers of search,
and many other services as well.
Being biggest doesn’t always mean being the best, though. When you’re evaluating the PPC companies
you may use, be sure to check not only the traffic rate, but also the conversion rate if possible.
It’s great if your ads receive lots of impressions, but if those impressions don’t turn to clicks, you’ll
find your PPC campaign is not at all effective.
Google AdWords. You may have heard the name so often that you think there’s nothing else — and
certainly it’s one of the most diverse PPC companies out there. It not only offers search engine marketing,
but also includes marketing by radio and even a telephone service that potential customers
can use to call you. Google will soon begin offering purchase of TV, newspaper, and embedded video
advertising. Even the radio and phone models of AdWords are charged on a bid-per-keyword basis.
Additionally, AdWords is linked to Google’s AdSense program, which is an advertisement publishing
program in which web-site owners place ads on their web sites; when users click through those ads
and make purchases, the web-site owner gets paid a small amount. Many web-site owners use this
service to help offset the cost of having a site.
AdWords ads are shown when someone searches on Google, AOL Search, Ask.com, and Netscape.
This gives Google AdWords one of the largest markets for keyword advertisements. However, a
larger market doesn’t guarantee a higher quality lead, so when using AdWords, it’s essential that
you pay attention to the details that help your ads place when they’re most effective.

Improving Click-Through Rates

Some of the efforts you take to reduce the cost of your PPC campaigns can also lead to improved
click-through rates. It’s essential that you work toward increasing these rates. Even though more
clicks drive up the cost of your PPC campaign, they also lead to more sales or conversions.
Aside from the efforts that you’ve already seen (like dayparting and better targeting) you can also
improve your click-through rates by improving the ad copy in your PPC campaigns.

Include special offers or incentives in ad text. If you have coupons to offer, discounts
available, or even free gifts with purchase or other special offers and incentives, be sure
those are included in your PPC ad text. People are drawn to specials, and advertising them
should draw more people to your site.
Consider including price in ads for products and services. Many people shy away from
advertising their prices, but those prices (especially if they’re real bargains) can entice customers.
If you have great prices, tell the world. Just make sure you check out the competition
before you decide you have the best prices on the Internet.

Improve the structure of your URLs

Creating descriptive categories and filenames for the documents on your website can not only help
you keep your site better organized, but it could also lead to better crawling of your documents by
search engines. Also, it can create easier, "friendlier" URLs for those that want to link to your content.
Visitors may be intimidated by extremely long and cryptic URLs that contain few recognizable words

www.example.com/products/bike-14.html
www.example.com/bikes/red-bicycles 


URLs like these can be confusing and unfriendly. Users would have a hard time reciting the URL from
memory or creating a link to it. Also, users may believe that a portion of the URL is unnecessary,
especially if the URL shows many unrecognizable parameters. They might leave off a part, breaking
the link.

Some users might link to your page using the URL of that page as the anchor text. If your URL
contains relevant words, this provides users and search engines with more information about the
page than an ID or oddly named parameter would.

Good practices for page title tags

• Accurately describe the page's content - Choose a title that effectively communicates the
topic of the page's content.
Avoid:
• choosing a title that has no relation to the content on the page
• using default or vague titles like "Untitled" or "New Page 1"

• Create unique title tags for each page - Each of your pages should ideally have a unique
title tag, which helps Google know how the page is distinct from the others on your site.
Avoid:
• using a single title tag across all of your site's pages or a large group of pages

• Use brief, but descriptive titles - Titles can be both short and informative. If the title is too
long, Google will show only a portion of it in the search result.
Avoid:
• using extremely lengthy titles that are unhelpful to users
• stuffing unneeded keywords in your title tags
Make use

Create uniqueand accurate page titles

A title tag tells both users and search engines what the topic of a particular page is. The <title> tag
should be placed within the <head> tag of the HTML document. Ideally, you should create a unique
title for each page on your site.

A relevant, deeper page (its title is unique to the content of the page) on our site appears as a
result

If the user clicks the result and visits the page, the page's title will appear at the top of the
browser

Titles for deeper pages on your site should accurately describe the focus of that particular page and
also might include your site or business name.


Alt tags in graphic links

An example of an alt tag might be the description of a picture of the Mona Lisa on your web site.
Your alt tag, then, should look like this:
Alt=”Mona Lisa”
The alt tag usually falls at the end of the image tag. An image tag might look something like this:
<img width=”100”
height=”100”
src=”monalisa.jpg”
alt=”Mona Lisa”>
The image code breaks down like this:
<img width=”100”: The width (in pixels) of the image.
Height=”100”: The height (in pixels) of the image.
Src=”monalisa.jpg”: The source of the image file.
Alt=”Mona Lisa”>: The alternative text that’s displayed when the image is not.

One more note about alt tags: To be really effective, these tags should be used for every single image
on your web site. That could become an arduous task if your site hasn’t been properly coded to start
with (and depending on the number of images that you have on your site). However, the addition of
these tags should be advantageous to your SEO efforts as long as you don’t overstep the unspoken
boundaries of alt tags.

Character Entities

 Character Entities

The following table lists the defined standard and proposed character entities for HTML and XHTML, as well as several that are nonstandard but generally supported.
Entity names, if defined, appear for their respective characters and can be used in the character-entity sequence &name; to define any character for display by the browser. Otherwise, or alternatively for named characters, use the character's three-digit numeral value in the sequence &#nnn; to specially define a character entity. Actual characters, however, may or may not be displayed by the browser, depending on the computer platform and user-selected font for display.
Not all 256 characters in the International Organization for Standardization (ISO) character set appear in the table. Missing ones are not recognized by the browser as either named or numeric entities.
To be sure that your documents are fully compliant with the HTML 4.0 and XHTML 1.0 standards, use only those named character entities with no entries in the Conformance column. Characters with a value of "!!!" in the Conformance column are not formally defined by the standards; use them at your own risk.
Numeric entity
Named entity
Symbol
Description
Conformance
&#009;
Horizontal tab
&#010;
Line feed
&#013;
Carriage return
&#032;
Space
&#033;
!
Exclamation point
&#034;
&quot;
"
Quotation mark
&#035;
#
Hash mark
&#036;
$
Dollar sign
&#037;
%
Percent sign
&#038;
&amp;
&
Ampersand
&#039;
'
Apostrophe
&#040;
(
Left parenthesis
&#041;
)
Right parenthesis
&#042;
*
Asterisk
&#043;
+
Plus sign
&#044;
,
Comma
&#045;
-
Hyphen
&#046;
.
Period
&#047;
/
Slash
&#048;-&#057;
09
Digits 09
&#058;
:
Colon
&#059;
;
Semicolon
&#060;
&lt;
<
Less than sign
&#061;
=
Equals sign
&#062;
&gt;
>
Greater than sign
&#063;
?
Question mark
&#064;
@
Commercial at sign
&#065;-&#090;
A-Z
Letters A-Z
&#091;
[
Left square bracket
&#92;
\
Backslash
&#093;
]
Right square bracket
&#094;
Caret
&#095;
_
Underscore
&#096;
`
Grave accent
&#097;-&#122;
a-z
Letters a-z
&#123;
{
Left curly brace
&#124;
|
Vertical bar
&#125;
}
Right curly brace
&#126;
~
Tilde
&#130;
,
Low left single quote
!!!
&#131;
Florin
!!!
&#132;
"
Low left double quote
!!!
&#133;
...
Ellipsis
!!!
&#134;
Dagger
!!!
&#135;
Double dagger
!!!
&#136;
^
Circumflex
!!!
&#137;
Permil
!!!
&#138;
Capital S, caron
!!!
&#139;
<
Less than sign
!!!
&#140;
Œ
Capital OE ligature
!!!
&#142;
Capital Z, caron
!!!
&#145;
'
Left single quote
!!!
&#146;
'
Right single quote
!!!
&#147;
"
Left double quote
!!!
&#148;
"
Right double quote
!!!
&#149;
Bullet
!!!
&#150;
En dash
!!!
&#151;
Em dash
!!!
&#152;
~
Tilde
!!!
&#153;
Trademark
!!!
&#154;
Small s, caron
!!!
&#155;
>
Greater than sign
!!!
&#156;
œ
Small oe ligature
!!!
&#158;
Small z, caron
!!!
&#159;
Capital Y, umlaut
!!!
&#160;
&nbsp;
Nonbreaking space
&#161;
&iexcl;
¡
Inverted exclamation point
&#162;
&cent;
¢
Cent sign
&#163;
&pound;
£
Pound sign
&#164;
&curren;
¤
General currency sign
&#165;
&yen;
¥
Yen sign
&#166;
&brvbar;
Broken vertical bar
&#167;
&sect;
§
Section sign
&#168;
&uml;
¨
Umlaut
&#169;
&copy;
©
Copyright
&#170;
&ordf;
ª
Feminine ordinal
&#171;
&laquo;
«
Left angle quote
&#172;
&not;
¬
Not sign
&#173;
&shy;
­
Soft hyphen
&#174;
&reg;
®
Registered trademark
&#175;
&macr;
¯
Macron accent
&#176;
&deg;
°
Degree sign
&#177;
&plusmn;
±
Plus or minus
&#178;
&sup2;
2
Superscript 2
&#179;
&sup3;
3
Superscript 3
&#180;
&acute;
´
Acute accent
&#181;
&micro;
μ
Micro sign (Greek mu)
&#182;
&para;
Paragraph sign
&#183;
&middot;
·
Middle dot
&#184;
&cedil;
,
Cedilla
&#185;
&sup1;
1
Superscript 1
&#186;
&ordm;
º
Masculine ordinal
&#187;
&raquo;
»
Right angle quote
&#188;
&frac14;
¼
Fraction one-fourth
&#189;
&frac12;
½;
Fraction one-half
&#190;
&frac34;
¾
Fraction three-fourths
&#191;
&iquest;
¿
Inverted question mark
&#192;
&Agrave;
À
Capital A, grave accent
&#193;
&Aacute;
Á
Capital A, acute accent
&#194;
&Acirc;
Â
Capital A, circumflex accent
&#195;
&Atilde;
Ã
Capital A, tilde
&#196;
&Auml;
Ä
Capital A, umlaut
&#197;
&Aring;
Å
Capital A, ring
&#198;
&AElig;
Æ
Capital AE ligature
&#199;
&Ccedil;
Ç
Capital C, cedilla
&#200;
&Egrave;
È
Capital E, grave accent
&#201;
&Eacute;
É
Capital E, acute accent
&#202;
&Ecirc;
Ê
Capital E, circumflex accent
&#203;
&Euml;
Ë
Capital E, umlaut
&#204;
&Igrave;
Ì
Capital I, grave accent
&#205;
&Iacute;
í
Capital I, acute accent
&#206;
&Icirc;
Î
Capital I, circumflex accent
&#207;
&Iuml;
Ï
Capital I, umlaut
&#208;
&ETH;
Capital eth, Icelandic
&#209;
&Ntilde;
Ñ
Capital N, tilde
&#210;
&Ograve;
Ò
Capital O, grave accent
&#211;
&Oacute;
Ó
Capital O, acute accent
&#212;
&Ocirc;
Ô
Capital O, circumflex accent
&#213;
&Otilde;
Õ
Capital O, tilde
&#214;
&Ouml;
Ö
Capital O, umlaut
&#215;
&times;
x
Multiply sign
&#216;
&Oslash;
Ø
Capital O, slash
&#217;
&Ugrave;
Ù
Capital U, grave accent
&#218;
&Uacute;
Ú
Capital U, acute accent
&#219;
&Ucirc;
û
Capital U, circumflex accent
&#220;
&Uuml;
Ü
Capital U, umlaut
&#221;
&Yacute;
Ý
Capital Y, acute accent
&#222;
&THORN;
Capital thorn, Icelandic
&#223;
&szlig;
ß
Small sz ligature, German
&#224;
&agrave;
à
Small a, grave accent
&#225;
&aacute;
á
Small a, acute accent
&#226;
&acirc;
â
Small a, circumflex accent
&#227;
&atilde;
ã
Small a, tilde
&#228;
&auml;
ä
Small a, umlaut
&#229;
&aring;
å
Small a, ring
&#230;
&aelig;
æ
Small ae ligature
&#231;
&ccedil;
ç
Small c, cedilla
&#232;
&egrave;
è
Small e, grave accent
&#233;
&eacute;
é
Small e, acute accent
&#234;
&ecirc;
ê
Small e, circumflex accent
&#235;
&euml;
ë
Small e, umlaut
&#236;
&igrave;
ì
Small i, grave accent
&#237;
&iacute;
í
Small i, acute accent
&#238;
&icirc;
î
Small i, circumflex accent
&#239;
&iuml;
î
Small i, umlaut
&#240;
&eth;
Small eth, Icelandic
&#241;
&ntilde;
ñ
Small n, tilde
&#242;
&ograve;
ò
Small o, grave accent
&#243;
&oacute;
ó
Small o, acute accent
&#244;
&ocirc;
ô
Small o, circumflex accent
&#245;
&otilde;
õ
Small o, tilde
&#246;
&ouml;
ö
Small o, umlaut
&#247;
&divide;
÷
Division sign
&#248;
&oslash;
Small o, slash
&#249;
&ugrave;
ù
Small u, grave accent
&#250;
&uacute;
ú
Small u, acute accent
&#251;
&ucirc;
Û
Small u, circumflex accent
&#252;
&uuml;
ü
Small u, umlaut
&#253;
&yacute;
y
Small y, acute accent
&#254;
&thorn;
Small thorn, Icelandic
&#255;
&yuml;
ÿ
Small y, umlaut