2. Rough Timeline of Web Technologies 1991 HTML 1994 HTML 2 1996 CSS1 + JavaScript 1997 HTML 4 1998 CSS 2 2000 XHTML 1 2002 Tableless Web Design 2005 AJAX 2009 HTML 5
17. New Selectors Finding elements by class (DOM API) var el = document.getElementById('section1'); el.focus(); varels = document.getElementsByTagName('div'); els[0].focus(); varels = document.getElementsByClassName('section'); els[0].focus(); Finding elements by CSS syntax (Selectors API) varels = document.querySelectorAll("ulli:nth-child(odd)"); varels = document.querySelectorAll("table.test > tr > td");
18. Web Storage // use localStorage for persistent storage // use sessionStorage for per tab storage textarea.addEventListener('keyup', function () { window.localStorage['value'] = area.value; window.localStorage['timestamp'] = (new Date()).getTime(); }, false); textarea.value = window.localStorage['value']; Save text value on the client side
19. Web SQL Database Var db = window.openDatabase(“Database Name”, “Database Version”); db.transaction(function(tx) { tx.executeSql(“SELECT * FROM test”, [], successCallback, errorCallback); }); If you try to open a database that doesn’t exist, the API will create it on the fly for you. You also don’t have to worry about closing databases. http://html5doctor.com/introducing-web-sql-databases/
21. Web Workers main.js: var worker = new Worker('extra_work.js'); worker.onmessage = function(event) { alert(event.data); }; extra_work.js: self.onmessage= function(event) { // Do some work. self.postMessage(some_data); }
22. Web Sockets var socket = new WebSocket(location); socket.onopen = function(event) { socket.postMessage(“Hello, WebSocket”); } socket.onmessage = function(event) { alert(event.data); } socket.onclose = function(event) { alert(“closed”); } Bi-directional, full-duplex communications channels, over a single Transmission Control Protocol (TCP) socket, designed to be implemented in webbrowsers and web servers.
23. Notifications if (window.webkitNotifications.checkPermission() == 0) { // you can pass any url as a parameter window.webkitNotifications.createNotification(tweet.picture, tweet.title, tweet.text).show(); } else { window.webkitNotifications.requestPermission(); } http://playground.html5rocks.com/#simple_notifications
24. Drag and drop document.addEventListener('dragstart', function(event) { event.dataTransfer.setData('text', 'Customized text'); event.dataTransfer.effectAllowed= 'copy'; }, false); http://playground.html5rocks.com/#drag_from_desktop
25. Geolocation if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var lat = position.coords.latitude; varlng = position.coords.longitude; var options = { position: new google.maps.LatLng(lat, lng) } var marker = new google.maps.Marker(options); marker.setMap(map); }); }