jQuery:history.back(1)问题 [英] jquery: history.back(1) issue

查看:115
本文介绍了jQuery:history.back(1)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jquery和history.back()时遇到问题:我有一个链接:

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

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

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

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

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

So I place a JS like this:

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

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

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

有没有一种方法可以在所有浏览器中使用它?或者上述代码中是否存在一些错误?

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

提前谢谢!

推荐答案

可能您缺少将event指定为函数参数,请尝试也指定以下内容:

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

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

换句话说,您在event.preventDefault();上遇到了问题,很可能阻止了下面的代码运行或工作.

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

这篇关于jQuery:history.back(1)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆