2010-10-04 43 views

回答

4

哇,我刚刚通过阅读本教程的JavaScript了解了很多。 它谈到了以下几件事:

掌握后退按钮使用JavaScript

  • window.onbeforeunload
  • 你真的,真的确定要离开我光辉的一页?
  • 当检测到用户点击取消
  • 真正的动态页面
  • 一些安全注意事项。
  • 你不能改变历史,最后
  • 如果你必须控制历史

其中谈到如何历史已与锁定。您可以进行有限的更改。但是你可以放置一个替换网址,这样如果一个人决定返回,它会将其重定向到一个不同的页面。如果一个人登录然后注销,而另一个人按下后退按钮,则该页面将被带到替换页面,这对于安全原因是有利的。

检查出来 它非常简短,精确,内容丰富的文章/教程,并包含许多Java片段,以帮助您为每个部分。

http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript

我希望这有助于。

PK

0

只能在你的html页面中实现一个“返回”链接,然后在那里添加你的JS功能。但是,在JS中无法检测到浏览器中用户正在做什么(例如,单击浏览器后退按钮),因为它发生在加载页面的上下文之外,并且没有标准规范向Web服务器提供数据从浏览器GUI。您可以尝试开发一个自定义插件,以便在浏览器上运行并向www服务器提供数据,但这又是一个非标准解决方案,并非所有用户都会非常轻松地安装第三方插件。

希望这会有所帮助。

1

我刚刚问了同样的问题,这得到了关闭,因为它是你的一个副本。这里是我的解决方案的本质:

表单字段自动从浏览器的缓存中获取,从而保存历史数据。虽然这是真的,但JavaScript代码每次都独立运行。

因此,我创建了一个小型隐藏字段来存放时间戳,并将其与JavaScript生成的数据时间进行比较。

下面是代码,我相信它可以更好的实现,虽然时间短:

$(document).ready(function() { 
    var date = new Date(); 
    var clientMiliseconds = date.getTime(); 
    clientMiliseconds = roundTime(clientMiliseconds); 
    var serverTimeStamp = $('#' + '<%= hfTimeStamp.ClientID %>').val(); 
    serverTimeStamp = roundTime(serverTimeStamp); 
    alert(serverTimeStamp == clientMiliseconds); 
}); 


function roundTime(time) { 
    time = Math.floor(time); 
    //since the server renders the time components a few seconds before the page is downloaded 
    //which also depends on where you assign the date on the serverside 
    //we've got a small inaccuracy of few seconds. we neglect these seconds, assuming that it would take the user 
    //a few seconds to click the back button 

    time = time/10000; 
    time = Math.floor(time); 
    return time; 
} 
相关问题