Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: history.back(1) issue

Tags:

jquery

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!

like image 735
Manuel Avatar asked Jul 05 '12 07:07

Manuel


People also ask

How do I go back to JQuery history?

history. back() is the same as history.go(-1) . history. back() is the same as clicking "Back" your browser.

What is history back ()?

The History. back() method causes the browser to move back one page in the session history. It has the same effect as calling history.go(-1) . If there is no previous page, this method call does nothing. This method is asynchronous.

What is the syntax and use of history back method?

HTML | DOM History back() Method The History back() method in HTML is used to load the previous URL in the history list. It has the same practical application as the back button in our web browsers. This method will not work if the previous page does not exist. This method does not contain any parameter.

How do I go back to previous page in JavaScript?

back() method: The back() method of the window. history object is used to go back to the previous page in the current session history.


1 Answers

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.

like image 111
Blaster Avatar answered Oct 05 '22 21:10

Blaster