/ Published in: JavaScript
Include the following code into the global scope of your page. It will make sure that by navigating using the browser back/forward buttons you will see the correct dynamic content. It will also make the dynamic content bookmarkable.
You'll have to change getContent() according to what content you want to load depending on the "descr" paramter describing the content. descr will be the text that will be added to the URL as hash
Expand |
Embed | Plain Text
var currHash = "#"; window.onload = function() { checkHash(); }; function getContent(descr) { switch(descr) { case "inhalt1" : document.getElementById('content').innerHTML = "<h2>Inhalt 1</h2>"; break; case "inhalt2" : document.getElementById('content').innerHTML = "<h2>Inhalt 2</h2>"; default: break; } window.location.hash = descr; currHash = "#" + descr; } setInterval(checkHash, 500); function checkHash() { if(window.location.hash && window.location.hash != currHash) { currHash = window.location.hash; getContent(window.location.hash.substring(1)); } }
You need to login to post a comment.
