
63
function displayContent(json) {
document.getElementById('headline1').innerHTML = json.feed.entry[0].gsx$content.$t;
document.getElementById('paragraph1').innerHTML = json.feed.entry[1].gsx$content.$t;
}
</script>
<script type="text/javascript"
src="http://spreadsheets.google.com/feeds/list/pgFb21wR3O90hBx3GJULxOQ/od6/public/
values?alt=json-in-script&callback=displayContent">
</script>
What does this JavaScript do? It requests a JSON data packet from the Google server and asks
for this data to be sent to the “displayContent” function you created. JSON is short for “JavaScript
Object Notation,” and it’s a data exchange format useful for JavaScript and other languages.
Now you can refresh the page and see that your headline and paragraph automatically adjust to the
spreadsheet values. And when anyone changes the spreadsheet data, your page will update itself too!
You should only share the spreadsheet with people you trust, because they can include HTML, and even
JavaScript, into your document. To protect yourself against undesirable HTML and JavaScript you can use a
JSON parser library at http://json.org/json2.js, which comes with usage examples right in the le.
There’s only one problem with using JavaScript: it executes inside the browser (on the client side)
and is therefore less accessible than static HTML. For instance, search engine bots will not be able ...