popstate

Chrome popstate not firing on Back Button if no user interaction

跟風遠走 提交于 2020-05-25 06:33:57
问题 I'm trying to use "pushState" and the "popstate" event to trap Back button navigation, however, while the popstate event triggers correctly in Firefox, it doesn't trigger in Chrome (Version 76.0.3809.87 (Official Build) (64-bit)) if there is no user interaction . From testing, it looks like the popstate event only gets triggered if the user interacts with the page (ie. clicks somewhere on the document). So if you load the page without interacting and hit Back, the popstate function is not

window.onpopstate is not working; nothing happens when I navigate back to page

人盡茶涼 提交于 2020-01-14 08:52:09
问题 I'm trying to add window.onpopstate on one of the pages on my site, but nothing is happening. I put this script on the page: <script type="text/javascript"> window.addEventListener('popstate', function(event) { if (event.state) { alert(event.state); } }, false); </script> I have also tried: <script type="text/javascript"> window.onpopstate = function() { alert("popped!"); } </script> However, I don't get any alerts when I navigate back to the page. 回答1: You get a popstate event only if you

Cannot find where I have a popstate loop creating multiple history entries

喜欢而已 提交于 2020-01-14 02:50:08
问题 I'm trying to create a single webpage that replaces the content of the main div when navigation links are clicked. I've been able to implement the pushstate function to replace the div content and change the url address pretty easily. I also am able to get the content to refresh when the back/forward buttons are clicked with the popstate function. However, now I click the first link and it works fine, I click the next link and it seems to apply 2 pushstates, the 3rd click, applies 3

Javascript history state incorrect

别来无恙 提交于 2019-12-23 09:02:13
问题 I am trying to populate the index of the currently selected tab using history.pushState({tabSelected: 1}, null, ""); I have a handler to the popstate event in jquery which programmatically switches the jquery ui tabs. $(window).bind("popstate", function(event) { var state = event.originalEvent.state; ... } This works fine and the browser and I am able to switch between tabs using back and forward buttons. Also works with two layers of tabs. But in certain cases I want to push additional state

pushState() and popState(): manipulating browsers' history

大城市里の小女人 提交于 2019-12-17 22:43:34
问题 I am working on a small project in which I want to create an Ajax-style website. Content is loaded with jQuery's load() . As some of you know, the down side of this is that the URL does not change accordingly to the content that is displayed. To make this work you can use pushState() . Because this is not cross-browser supported, I used the plug-in history.js . This is working quite nicely, but the problem is that my back and forward buttons are not working as they should and I have no idea

binding popstate event not working

十年热恋 提交于 2019-12-07 01:34:00
问题 I have tried to type this code into the browser's console: window.onpopstate = function() {alert(1);} and then click the back button. No alert has shown. Am I doing something wrong? Or is it not allowed to bind popstate event to a page from console? Using Chrome 24 and Firefox 18 回答1: Type this into the console window.onpopstate = function() {alert(1);}; history.pushState({}, ''); then click the back button. 回答2: I prefer adding the popstate listener as follows, to prevent overwriting of what

Check if user logged in on ajax page change

别等时光非礼了梦想. 提交于 2019-12-06 12:00:55
问题 As part of a webapp I'm building I'll need to check if the user is logged in whenever they change page. On a normal non-ajax site this is easy because I can just place the PHP session conditional statement in the header, and the header being called on every page change will determine whether the login page is displayed or not, but seeing as the header file is only set once within an ajax application, which is on the initial load, how can I check whenever the user makes an ajax page request

binding popstate event not working

◇◆丶佛笑我妖孽 提交于 2019-12-05 05:46:31
I have tried to type this code into the browser's console: window.onpopstate = function() {alert(1);} and then click the back button. No alert has shown. Am I doing something wrong? Or is it not allowed to bind popstate event to a page from console? Using Chrome 24 and Firefox 18 Type this into the console window.onpopstate = function() {alert(1);}; history.pushState({}, ''); then click the back button. I prefer adding the popstate listener as follows, to prevent overwriting of what's already in window.onpopstate : window.addEventListener('popstate', function(){alert(1);}); 来源: https:/

Check if user logged in on ajax page change

心不动则不痛 提交于 2019-12-04 15:11:11
As part of a webapp I'm building I'll need to check if the user is logged in whenever they change page. On a normal non-ajax site this is easy because I can just place the PHP session conditional statement in the header, and the header being called on every page change will determine whether the login page is displayed or not, but seeing as the header file is only set once within an ajax application, which is on the initial load, how can I check whenever the user makes an ajax page request whether or not the session is still valid? Since I'm using pushState and popState I know I can set the

In iOS 7 Safari, how do you differentiate popstate events via edge swipe vs. the back/fwd buttons?

家住魔仙堡 提交于 2019-12-04 11:13:00
问题 In iOS 7 Safari there are now two ways to navigate back/forward -- using the traditional back/forward button arrows at the bottom or by swiping from the edge of the screen. I'm using an animation to transition between pages in my ajax app, but I don't want to fire that transition if users are navigating via the edge swipe, because that is an animation itself. However, the popstate event objects appear to be identical for both types of navigation -- is there any way to differentiate between