javascript - Can I prevent history.popstate from triggering on initial page-load? -


i'm working on site serves content via ajax.

if click item in menu, content div gets updated $.get response, nothing fancy.

i'm implementing history.pushstate allow navigation browser's back/forward button.

i have following load content on history navigation:

$(function() {     $(window).bind("popstate", function() {         $.getscript(location.href);      }); }); 

the problem is, when page loaded first time, function $.getscript page loaded again. first time page loaded renders initial html view, on second load renders js view, since js request.

how prevent event firing on pages html requests?

using native html5 history api you're going run problems, every html5 browser handles api little bit differently can't code once , expect work without implementing workarounds. history.js provides cross-browser api html5 history api , optional hashchange fallback html4 browsers if want go down route.

for upgrading website ria/ajax-application can use code snippet: https://github.com/browserstate/ajaxify

which part of longer article intelligent state handling goes explanations hashbang, hashes , html5 history api.

let me know if need further :) cheers.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -