Skip to content

Commit

Permalink
Using pushState to update the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
beaucollins committed May 1, 2012
1 parent 2629e3c commit 4a7846f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions public/app.js
Expand Up @@ -216,8 +216,19 @@ var loadSite = function(src){

document.querySelector('form').addEventListener('submit', function(e){
e.preventDefault();
if (window.history.pushState) {
window.history.pushState({url:this.site.value}, null, "?" + this.site.value);
};
loadSite(this.site.value);
});

window.addEventListener('popstate', function(e){
if (e.state && e.state.url) {
console.log("State", e.state);
document.forms[0].site.value = e.state.url;
loadSite(e.state.url)
};
});

window.addEventListener('resize', function(){
span.textContent = iframe.offsetWidth + 'px';
Expand Down

0 comments on commit 4a7846f

Please sign in to comment.