jquery: history.back(1) issue

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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

<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).

So I place a JS like this:

$("#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!

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

Thanks in advance!

回答1:

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

$("#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.



回答2:

An easy method:

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


回答3:

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?



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!