javascript - How to stop an <a> tag from loading a new page with html5 history api -


i trying out the history api changing url after swapping out content , have run issue stopping tags loading new page. far, when click button, loads requested content within page loads page requested content stored. suggestions how stop , result of webpage new content , fresh url can shared?

here's js.

function supports_history_api() { return !!(window.history && history.pushstate); }  function swaptext(href) { var req = new xmlhttprequest(); req.open("get",        "http://bonkmas.com/historytest/gallery/" +          href.split("/").pop(),        false); req.send(null); if (req.status == 200) { document.getelementbyid("open-content").innerhtml = req.responsetext; setuphistoryclicks(); return true; } return false; }  function addclicker(link) { link.addeventlistener("click", function(e) { if (swaptext(link.href)) {   history.pushstate(null, null, link.href);   e.preventdefault(); } }, true); }  function setuphistoryclicks() {   addclicker(document.getelementbyid("next-vid"));   addclicker(document.getelementbyid("previous-vid")); }  window.onload = function() { if (!supports_history_api()) { return; }  setuphistoryclicks();  window.settimeout(function() { window.addeventlistener("popstate", function(e) {   swaptext(location.pathname); }, false); }, 1); } 

http://bonkmas.com/historytest/

this because scope broken, in click listener need use "this" access link element. because of exception following code not executed.

use firebug or chrome developer tools debug code, they'll brake/pause on exceptions.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -