当使用file://协议时,我可以使用history.back()函数在Chrome中工作吗? [英] Can I get the history.back() function to work in Chrome when using the file:// protocol?
问题描述
我在限制使用本地文件系统和浏览器的环境中构建应用程序(即运行服务器不是选项)。我在主要调用 history.back()
的许多页面上都有一个通用的返回链接。它看起来如下所示:
I'm building an application in an environment where I'm restricted to using the local file system and a browser (i.e. running a server isn't an option). I have a generic 'go back' link on numerous pages that mainly just calls history.back()
. It looks something like the following:
function goBack(evt) {
// Check to see if override is needed here
// If no override needed, call history.back()
history.back();
}
$('#my-back-button').click(goBack);
这段代码在Firefox和IE6中运行良好(不要求),但在Chrome中失败。任何关于为什么和/或可能的解决方法的建议?
This code works fine in Firefox and IE6 (don't ask), but fails in Chrome. Any suggestions as to why and/or possible workarounds?
我也试过 history.go(-1); $ c $
I've also tried history.go(-1);
which does not work either.
推荐答案
出于某种原因在Chrome中,您必须在调用history.go后添加返回false (-1)
For some reason in chrome, you have to add return false after calling history.go(-1)
将您的函数更改为:
Change your function to:
function goBack(evt) {
// Check to see if override is needed here
// If no override needed, call history.back()
history.go(-1);
return false;
}
这篇关于当使用file://协议时,我可以使用history.back()函数在Chrome中工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!