Practice exercises CHAPTER 15 569
C. An iframe on the same page whose source is within the same domain
D. The operating system that is hosting the browser
- Which of the following is the correct way to cancel a storage event?
A. event.returnValue = false;
B. event.preventDefault();
C. event.stopPropagation();
D. Storage events cannot be canceled after they are triggered.
Practice exercises
If you encounter a problem completing any of these exercises, the completed projects can be
installed from the Practice Exercises folder that is provided with the companion content.
Exercise 1: Create a contact book by using localStorage
In this exercise, you practice working with web storage by creating a simple contact list that
is persisted as an array in localStorage. The page will display the complete contact list within a
grid and use a form for adding and editing contacts. The website itself will consist of a single
page; no server-side logic is needed. The HTML and CSS code is already complete, so your
focus is on adding the JavaScript needed to make it work.
- Open Visual Studio Express 2012 for Web. Click File and choose Open Project. Navigate
to the ContactBook folder under the Exercise1Start folder. Select ContactBook.sln and
click Open. - Review the starting default.html file.
This file has a reference to the default.css file, the jQuery file, and the ContactsLibrary.
js file. In the element is a contacts table and a form that includes fields for first
name, last name, email, and phone number of the contact as follows.
<!DOCTYPE html>
Contact Book
Contacts