Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson)...
-
Upload
raymond-carroll -
Category
Documents
-
view
214 -
download
1
Transcript of Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson)...
![Page 1: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/1.jpg)
Those Who Control The Past Control The Future:The HTML5 History API
Sean Adkinson (@seanadkinson)
Jama Software
2012 HTML5 Developer Conference
![Page 2: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/2.jpg)
What is it?
The HTML5 History API gives JavaScript the ability to control
the browser’s URL
…without reloading the page
![Page 3: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/3.jpg)
Why History API now?
AJAX and single-page applications
New resources should have new URLs
The History API gives you the ability to use AJAX, and maintain proper URLs
![Page 4: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/4.jpg)
“#!” Solution
Uses browser in-page link functionality
Problems with this solutionOnly accessible to the clientDoesn’t work without JavaScriptCan’t use browser in-page linksIt’s a hack
![Page 5: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/5.jpg)
History API Spec
Two additional window.history methods
One additional window event
![Page 6: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/6.jpg)
Push Statewindow.history.pushState(data, title,
path);
![Page 7: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/7.jpg)
Replace Statewindow.history.replaceState(data,
title, path);
![Page 8: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/8.jpg)
Pop Statewindow.onpopstate =
function(event);
demo
![Page 9: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/9.jpg)
Single-Page Strategy
URL State, one-to-one
When state is changed, push new corresponding URL
On pop state (and initial page load), display based on URL State
If starting a new project, just use a framework like Backbone
demo
![Page 10: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/10.jpg)
Multi-Page Strategy
Intercept link clicks
Retrieve and display contentBack-end returns only HTML
Push/replace state
Github is a great exampledemo
![Page 11: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/11.jpg)
Browser SupportInternet Explorer None
Firefox 4.0+
Safari 5.0+
Chrome 8.0+
Opera 11.50+
iPhone 4.2.1+
Android None
![Page 12: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/12.jpg)
History.js
Abstraction layerHistory.pushState(data, title, url);History.replaceState(data, title, url);window.onstatechange
URLs can be pasted between IE Firefox
Adapters for jQuery, Zepto, MooTools, more
http://bit.ly/historyjs
![Page 13: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/13.jpg)
References
http://diveintohtml5.info/history.html
http://html5doctor.com/history-api/
https://github.com/balupton/History.js/
![Page 14: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/14.jpg)
Sean Adkinson
Jama Software@seanadkinson
![Page 15: Those Who Control The Past Control The Future: The HTML5 History API Sean Adkinson (@seanadkinson) Jama Software 2012 HTML5 Developer Conference.](https://reader036.fdocuments.us/reader036/viewer/2022082819/56649e015503460f94aeb3bd/html5/thumbnails/15.jpg)
Questions?