browser-state

Does back/forward in the browser change javascript variables?

心已入冬 提交于 2019-11-29 22:26:35
问题 <script type="text/javascript> var x = 0; //this occurs in the beginning of the page. $("#button").onclick{ x = 1; } </script> Let's say the variable "x" changes to 1. Then the user clicks a link. When the user clicks "back", will x be 0 or 1? 回答1: It will be 0 . The browser does not cache the state of Javascript variables between page loads. Update This is not the case in browsers such as Firefox. Please see Trey's answer. 回答2: As detailed in another question, the real answer to this

Can you use hash navigation without affecting history?

谁都会走 提交于 2019-11-28 03:03:18
I'm afraid it might be impossible but is there a way to change the hash value of a URL without leaving an entry in the browser's history and without reloading ? Or do the equivalent? As far as specifics go, I was developing some basic hash navigation along the lines of: //hash nav -- works with js-tabs var getHash = window.location.hash; var hashPref = "tab-"; function useHash(newHash) { //set js-tab according to hash newHash = newHash.replace('#'+hashPref, ''); $("#tabs li a[href='"+ newHash +"']").click(); } function setHash(newHash) { //set hash according to js-tab window.location.hash =

jQuery - hashchange event

风流意气都作罢 提交于 2019-11-26 12:58:38
I am using: $(window).bind( 'hashchange', function(e) { }); to bind a function to the hash change event. This seems to work in IE8, Firefox and Chrome, but not in Safari and I assume not in earlier version of IE. For these browsers, I want to disable my JavaScript code that uses the hash and hashchange event. Is there a way with jQuery that i can detect if the browser supports the hashchange event? Maybe something with jQuery.support ... You can detect if the browser supports the event by: if ("onhashchange" in window) { //... } See also: Detecting event support without browser sniffing

jQuery - hashchange event

你。 提交于 2019-11-26 05:54:23
问题 I am using: $(window).bind( \'hashchange\', function(e) { }); to bind a function to the hash change event. This seems to work in IE8, Firefox and Chrome, but not in Safari and I assume not in earlier version of IE. For these browsers, I want to disable my JavaScript code that uses the hash and hashchange event. Is there a way with jQuery that i can detect if the browser supports the hashchange event? Maybe something with jQuery.support ... 回答1: You can detect if the browser supports the event