History. Go (-1) parsing in different browsers

Source: Internet
Author: User

Today I encountered a problem:

<A href = "#" onclick = "history. Go (-1)"> back </a>

When you click "back", under IE and firefix, history. go (-1) can play the role of backend, but it does not work in chrome, use history. go (-2) takes effect.

Later, I studied it and found that in IE and firefix, it was resolved to execute the onclick event, that is, execute history. the Go (-1) page jumps away and does not execute the href of the <A> tag. However, in chrome, not only the onclick event is executed, but also the href of the <A> tag is executed. Therefore, we need to add return false to The onclick event to prevent <A> tag href from being triggered. That is:

<A href = "#" onclick = "history. Go (-1); Return fasle"> back </a>

Or:

<A href = "javascript: void (0)" onclick = "history. Go (-1)"> back </a>

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.