English 中文(简体)
历史是这样。 j 了解后纽顿何时受到压制
原标题:Is there a way in History.js to know when the back button was pressed

I ve开始测试History.js。 在了解如何操作和没有<代码>popstate后,有statechange。 当浏览器的背顿受到压力时,我会寻求一种不同的方式。

原因是,我需要先了解卢爱拉,然后从一米进入。 gist 该项目只包括我们将要研究的URL。

我希望,解决办法不是追踪全球变量中最近访问的URL。

增 编

最佳回答
问题回答

我认为,就我而言,光顾问题的解决办法是微不足道的。 我创造了一种永远真实的ool,但我利用历史改变国家之前的权利除外。

var manualStateChange = true;

History.Adapter.bind(window, statechange ,function(){
    if(manualStateChange == true){
     // BACK BUTTON WAS PRESSED
    }
    manualStateChange = true;
});

无论何时,我都会从方案上改变国家,把ool弄成虚假:

manualStateChange = false;
History.pushState(null, null, currentPath);

我知道这是一个很突出的问题,但我在从标准页到历史页之间转换时,就着手解决了背部/前纽州的问题。

Scenario: Use HTML5 History (or history.js plugin) on a set of pages Then other pages we need real loads, aka a standard page (don t ask why, but there are certain use cases that this may be needed)

当你从历史的一页起,确实装上标准一页。 你们不能去BACK:它改变了ur,但只把 page装在火上;我假定这是最初员额的问题。 我的个人意见是,这是一个浏览器泡沫(所有浏览器都有问题),因为浏览器应当知道你重新登上的那一页是在历史页之外再上载的。

I fixed this with something really simple: Listening to the statechange event and tell the browser to refresh when it does fire. This way I don t care if they go back or forward out of this page. If the browser thinks the state is changing (links don t fire the statechange event), only back/forward INTO a History state page fires this event, so it solves the issue.

Code, using jQuery + History.js plugin:

$(window).on( statechange , function() {
    window.location.reload();
});

如果这样说,你可能不会有这个问题。 然而,我注意到,在许多网站do <>>>使用超文本5历史(如果你在图像模式上重载,然后试图回来,这个问题就存在)。

Hopefully, if you do have this issue, you ll find this answer and have a huge sigh of relief :)

In the offical version this feature is not available. Try to use this file in the main while: https://github.com/danger89/history.js/blob/master/scripts/bundled/html5/jquery.history.js

I can t guarantee that his solution works for every browser. But it s a nice solution. If you applied his changes, you can use:

var State = History.getState();
if (State.navigation) {
    // Back / forward button is pressed.
}

更多信息可在

Similar answer than that of James Wagoner. the statechange event was being fired both ways, so instead I only check for a popstate event, which in my case is only called when the user goes back.

window.addEventListener( popstate , function() {
  window.location.reload();
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签