html5 js apis
DESCRIPTION
Standards.next for HTML5 JavaScript APIsTRANSCRIPT
![Page 1: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/1.jpg)
JavaScript APIsHTML5
Remy Sharp@rem
standards.next
![Page 2: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/2.jpg)
JavaScript APIsHTML5
Remy Sharp@rem
standards.next
& friends!
![Page 3: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/3.jpg)
HTML5: 2022?
![Page 4: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/4.jpg)
Bollocks.
![Page 5: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/5.jpg)
APIs
•Canvas
•Drag & Drop
•History
•Inline Editing
•Messaging
•Of!ine Apps
•Video & Audio
•Geolocation
•Local Storage
•Selectors
•Server Events
•Web Sockets
•Workers
![Page 6: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/6.jpg)
APIs
•Canvas
•Drag & Drop
•History
•Inline Editing
•Messaging
•Of!ine Apps
•Video & Audio
•Geolocation
•Local Storage
•Selectors
•Server Events
•Web Sockets
•Workers
![Page 7: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/7.jpg)
APIs
•Canvas
•Drag & Drop
•History
•Inline Editing
•Messaging
•Of!ine Apps
•Video & Audio
•Geolocation
•Local Storage
•Selectors
•Server Events
•Web Sockets
•Workers
![Page 8: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/8.jpg)
APIs
•Canvas
•Drag & Drop
•History
•Inline Editing
•Messaging
•Of!ine Apps
•Video & Audio
•Geolocation
•Local Storage
•Selectors
•Server Events
•Web Sockets
•Workers
![Page 9: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/9.jpg)
APIs
•Canvas
•Drag & Drop
•History
•Inline Editing
•Messaging
•Of!ine Apps
•Video & Audio
•Geolocation
•Local Storage
•Selectors
•Server Events
•Web Sockets
•Workers
?
![Page 10: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/10.jpg)
Documentation
![Page 11: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/11.jpg)
www.whatwg.org/html5/
dev.w3.org/html5/
irc://irc.freenode.net/#whatwg
![Page 12: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/12.jpg)
![Page 13: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/13.jpg)
![Page 14: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/14.jpg)
![Page 15: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/15.jpg)
Canvas
![Page 16: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/16.jpg)
Canvas
![Page 17: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/17.jpg)
document.querySelector('canvas').getContext("2d")
http://tr.im/pRkz
![Page 18: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/18.jpg)
document.querySelector('canvas').getContext("2d")
http://tr.im/pRkz
![Page 19: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/19.jpg)
Drag'n Drop
![Page 20: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/20.jpg)
Drag'n Drop
![Page 21: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/21.jpg)
Drag & Drop
•draggable="true"
•events: dragstart, drop, etc
•event.transferData
![Page 22: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/22.jpg)
<div draggable="true">drag me</div>
<script>
document.querySelector('div').addEventListener(
"dragstart",
function (e) {
e.dataTransfer.setData("arbitrary","data");
return true;
},
true);
</script>
![Page 23: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/23.jpg)
<div draggable="true">drag me</div>
<script>
document.querySelector('div').addEventListener(
"dragstart",
function (e) {
e.dataTransfer.setData("arbitrary","data");
return true;
},
true);
</script>
???
![Page 24: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/24.jpg)
el.addEventListener('dragover', function (e) {
e.preventDefault();
}, true);
el.addEventListener('drop', function (e) {
e.stopPropagation();
alert(e.dataTransfer.getData('arbitrary'));
}, true);
![Page 25: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/25.jpg)
el.addEventListener('dragover', function (e) {
e.preventDefault();
}, true);
el.addEventListener('drop', function (e) {
e.stopPropagation();
alert(e.dataTransfer.getData('arbitrary'));
}, true);
![Page 26: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/26.jpg)
el.addEventListener('dragover', function (e) {
e.preventDefault();
}, true);
el.addEventListener('drop', function (e) {
e.stopPropagation();
alert(e.dataTransfer.getData('arbitrary'));
}, true);
![Page 29: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/29.jpg)
Of!ine Applications
![Page 30: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/30.jpg)
Of!ine Applications
![Page 31: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/31.jpg)
Of!ine Apps
•Application cache
•Events: of!ine, online
•navigator.onLine property
![Page 32: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/32.jpg)
Enable
<html manifest="my.manifest">
![Page 33: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/33.jpg)
CACHE MANIFEST
images/shade.jpg
images/bin.jpg
my.manifest
![Page 34: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/34.jpg)
Cache
•First line: CACHE MANIFEST
•Requires text/cache-manifest
•Recommend using versioning
•window.applicationCache
![Page 35: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/35.jpg)
Cache
•On load will hit my.manifest
![Page 36: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/36.jpg)
Cache
•On load will hit my.manifest
•Change manifest: trigger reload
![Page 37: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/37.jpg)
Cache
•On load will hit my.manifest
•Change manifest: trigger reload
•applicationCache.update() force
![Page 38: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/38.jpg)
Cache
•On load will hit my.manifest
•Change manifest: trigger reload
•applicationCache.update() force
•Cache events
![Page 39: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/39.jpg)
![Page 40: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/40.jpg)
![Page 41: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/41.jpg)
Firefox
![Page 42: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/42.jpg)
window.addEventListener( 'offline', // online too online, // function true);
![Page 43: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/43.jpg)
function online() {
if (navigator.onLine == false) {
// gone offline
} else {
// else we're online
}
}
![Page 46: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/46.jpg)
navigator.onLine
![Page 47: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/47.jpg)
Geolocation
![Page 48: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/48.jpg)
Geolocation
![Page 49: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/49.jpg)
Not always accurate!
![Page 50: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/50.jpg)
![Page 51: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/51.jpg)
navigator .geolocation .getCurrentPosition( success, err );
![Page 52: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/52.jpg)
![Page 53: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/53.jpg)
![Page 54: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/54.jpg)
Messaging
![Page 55: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/55.jpg)
Messaging
![Page 56: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/56.jpg)
Messaging
•Communicate across domains
•Across window object
•With Workers
•String transfer only
![Page 57: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/57.jpg)
.postMessage(str)
.onMessage(event)event.data == str
![Page 58: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/58.jpg)
Cross Domain
document .getElementById("iframe") .contentWindow .postMessage("my message");
![Page 59: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/59.jpg)
The Catcher
window.addEventListener( "message", function(e){ if (e.origin !== "http://example.com") { return; }
alert(e.origin + " said: " + e.data); }, false);
![Page 60: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/60.jpg)
Web Workers
![Page 61: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/61.jpg)
Web Workers
![Page 62: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/62.jpg)
•Threads
![Page 63: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/63.jpg)
•Threads
•Native or via Gears
![Page 64: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/64.jpg)
•Threads
•Native or via Gears
•Sandboxed
![Page 65: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/65.jpg)
•Threads
•Native or via Gears
•Sandboxed
•Debugging?
![Page 66: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/66.jpg)
•importScripts
•postMessage
•onmessage
•onconnect
![Page 67: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/67.jpg)
Without
![Page 69: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/69.jpg)
Storage
![Page 70: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/70.jpg)
Storage
![Page 71: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/71.jpg)
1. sessionStorage
![Page 72: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/72.jpg)
1. sessionStorage
2. localStorage
![Page 73: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/73.jpg)
1. sessionStorage
2. localStorage
3. database storage
![Page 74: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/74.jpg)
Storage
sessionStorage.setItem(key, value)
sessionStorage.getItem(key)
![Page 75: HTML5 JS APIs](https://reader031.vdocument.in/reader031/viewer/2022013121/540e27c88d7f72767e8b4c4d/html5/thumbnails/75.jpg)
Storage
localStorage.setItem(key, value)
localStorage.getItem(key)