JavaScript history.back () invalid solution in Firefox and Chrome

Source: Internet
Author: User

Today in an app test to use to return to the previous source page of a function, but after testing history.back () found in IE effective in Firefox and chrome invalid, below we see how to solve the problem.

The original notation is History.back () as follows

Htm

<div class= "btn1" ><a href= "#" id= "Calcelbtn" > Cancel </a></div>

JS Code

$ (' #calcelbtn '). Click (function () {
History.back ();
})

After the test found in IE can be used, in Firefox and Chrome is invalid, later Baidu discovered to be in accordance with the following method is not invalid in Firefox and Chrome support.

FireFox:

Just change it to the following way:

<a href= "#" onclick= "Window.history.back ()" > Back </a>

Chrome:

Chrome is more difficult than Firefox:

<a href= "#" onclick= "Window.history.back (); return false; " > Back </a>

Human analysis: For Chrome, the first execution of Window.history.back (), after the completion of the execution of the href= "#", it cannot be returned. Plus return false will no longer execute href= "#" Okay, let's do some fixing.

$ (' #calcelbtn '). Click (function () {
Window.history.back ();
return false;
})

JavaScript history.back () invalid solution in Firefox and Chrome

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.