jquery:history.back(1) 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11339781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:29:49  来源:igfitidea点击:

jquery: history.back(1) issue

jquery

提问by Manuel

I have an issue with jquery and history.back(): I got a link:

我有 jquery 和 history.back() 的问题:我得到了一个链接:

<a href="#" id="backLink">Link back</a>

I cant use something like href="javascript:history.back()" as the CMS used is blocking inline JS (for whatever reason).

我不能使用诸如 href="javascript:history.back()" 之类的东西,因为所使用的 CMS 会阻止内联 JS(无论出于何种原因)。

So I place a JS like this:

所以我放置了一个这样的 JS:

$("#backLink").click(function() {
    event.preventDefault();
    history.back(1);
});

But this does not seem to work! On Safari and Chrome no problem, but on FF, IE this link is not working!

但这似乎不起作用!在 Safari 和 Chrome 上没问题,但在 FF、IE 上此链接不起作用!

Is there a way how to use this for all browsers - or is there some mistake in the above code?

有没有办法在所有浏览器上使用它 - 或者上面的代码有什么错误?

Thanks in advance!

提前致谢!

回答by Blaster

Probably you are missing to specify eventas function argument, try specifying that too:

可能您缺少指定event为函数参数,也尝试指定它:

$("#backLink").click(function(event) {
    event.preventDefault();
    history.back(1);
});

In other words, you had problem on event.preventDefault();which most likely prevented below code from running or working.

换句话说,您遇到了event.preventDefault();最有可能阻止以下代码运行或工作的问题。

回答by Manuel

An easy method:

一个简单的方法:

 <a href="javascript: history.go(1)" id="backLink">Link back</a>

回答by SMut

I'd try:

我会尝试:

javascript: history.back(1)

otherwise using:

否则使用:

javascript: history.go(1)

the browser will stay where it is. That's not really what was initially requested, is it?

浏览器将保持原样。这不是最初的要求,是吗?