HTML and CSS Reference
In-Depth Information
Objective 1.4: Thought experiment
This is a simple example of the power available when combining the HTML5 APIs. You can use
the Web Storage API to store the location points as they occur from the Geolocation API by
using the watchPosition method. The following code demonstrates the storage of the data:
<script>
var watcher;
var geoLocator;
var positions = 0;
window.onload = function () {
geoLocator = window.navigator.geolocation;
var posOptions = { enableHighAccuracy: true, timeout: 45000 };
watcher = geoLocator.watchPosition(successPosition, errorPosition,
posOptions);
}
function successPosition(pos) {
//on each position, store it into local storage sequentially.
//Then it can be retrieved sequentially
//in order to redraw the route on a map.
var p = "Lat: " + pos.coords.latitude + " Long: " + pos.coords.longitude;
localStorage.setItem(position, p);
}
function errorPosition(err) {
var sp = document.createElement("p");
sp.innerText = "error: " + err.message; + " code: " + err.code;
document.getElementById("geoResults").appendChild(sp);
}
</script>
Objective 1.4: Review
Correct answer: C
1.
Incorrect: localStorage is persistent even after the session closes.
A.
Incorrect: cookieStorage doesn't exist in the Web Storage API.
B.
Correct: sessionStorage clears when the session closes.
C.
Incorrect: A hidden input element isn't a valid solution to meet the requirement.
D.
Correct answer: C
2.
Incorrect: The offLine property isn't a valid JavaScript option.
A.
Incorrect: You wouldn't specify the manifest on the <form> element.
B.
Correct: Specifying the manifest attribute on the HTML element is the correct
action.
C.
Incorrect: The browser's offline option doesn't invoke the AppCache API.
D.
Search WWH ::




Custom Search