10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

<strong>With</strong>in the section of the HTML document, you have a tag that contains some basic<br />

JavaScript. In this case, a simple alert box is displayed with the text “Hi, I am some simple JavaScript.”<br />

tags are the primary way of including scripted content in your HTML pages. You also have a<br />

type attribute on the tag that has been set to "text/Javascript" to signify the type of script<br />

you will be including within the tag. Current standards specify that you should use this type<br />

of script attribute setting for all JavaScript script and, additionally, place the tag within the<br />

section of the document (this is actually a semantic guideline and not a compliance requirement).<br />

Previously, this was not required, as shown in the following code:<br />

<br />

<br />

<br />

Basic Javascript<br />

<br />

alert(“Hi, I am some simple JavaScript”);<br />

<br />

<br />

<br />

<br />

alert(“Alert box 2”);<br />

<br />

Simple Javascript Page<br />

<br />

alert(“Alert box 3”);<br />

<br />

<br />

<br />

Although they are not strictly necessary, and despite the fact that many browsers will work fine without<br />

adhering to these standards, the recommended approach is to adhere to these standards for any current<br />

and future web development.<br />

You will notice in the previous example, that we specified a language attribute with a value of<br />

"javascript" instead of a type attribute with a value of "text/javascript". The script still works<br />

fine; however, this requires that each tag have a type attribute with the specified MIME type<br />

to be contained within the tag. There are some processing differences between the use of the<br />

language and type attributes; however, current standards dictate the use of the type attribute, and<br />

that’s what will be used throughout this book.<br />

XHTML is the most recent version of HTML and describes or reformulates HTML elements more<br />

inline with XML semantics and form. It also enhances the separation of structure from presentation.<br />

More information can be found at www.w3.org/TR/xhtml1.<br />

One of the most important attributes of a tag is the src attribute. You may remember in the<br />

last chapter using the src attribute with the tag. The functionality is similar here. This provides<br />

the ability to include JavaScript from external files and is a great way to centralize and share common<br />

JavaScript code.<br />

<br />

32

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!