22.04.2013 Views

HTML, XHTML & CSS

HTML, XHTML & CSS

HTML, XHTML & CSS

SHOW MORE
SHOW LESS

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

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

74<br />

Part IV: Scripting and (X)<strong>HTML</strong><br />

Unlike preceding examples, Listing 16-3 has a section in both the<br />

head and the body:<br />

✓ Cookies are read and written in the header script when the page loads.<br />

✓ The body script dynamically writes out the contents of the page itself.<br />

Follow these steps to add the cookie-handling script to your page:<br />

1. Copy both sections and put them into the appropriate parts<br />

of your page.<br />

2. Change the section to contain the text that you want the page<br />

to display.<br />

The lines inside the document.write() statements write the text out<br />

to the document on the fly.<br />

A cookie has an expiration date, after which it’s no longer available. This<br />

example creates cookies that expire in six months. If you want your cookies<br />

to live longer (or not so long), adjust the JavaScript code near the top that<br />

sets a value for expireDate. Thus, the following example increases the current<br />

expiration date by six months:<br />

expireDate.setMonth(expireDate.getMonth()+6)<br />

Working with jQuery and FancyBox Lightbox<br />

In days of yore, it was commonplace to use browser pop-ups to present additional<br />

information about your Web site. In fact, we even used this technique<br />

in the last edition of this book. Owing to overuse at some unscrupulous<br />

Web sites, plus their annoying in-your-face nature, pop-ups are now mostly<br />

blocked by major browsers . . . and that’s probably a good thing!<br />

Instead of pop-ups, we now recommend using lightboxes. This may sound<br />

like a weapon out of Star Wars or a tool used by photographers (that last<br />

guess is close). In this case, however, a lightbox is a tool that displays images,<br />

<strong>HTML</strong> content, and multimedia atop of a Web page.<br />

Dozens of different lightboxes are available on the Internet. Please use your<br />

favorite search engine to check those out if you want to know more. Here, we<br />

only discuss jQuery and FancyBox.<br />

If you’re unfamiliar with jQuery, think of it as a popular JavaScript library<br />

that you can reference without writing much real code yourself. (We don’t<br />

dig much into jQuery in this book, but you need only do a Web search on this

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

Saved successfully!

Ooh no, something went wrong!