JavaScript unlink default behavior problem

Source: Internet
Author: User

A problem was encountered today when testing the 69th page of the JavaScript Dom Programming Art (2nd edition). The expected effect should be to click the link does not jump to the current page, but also pop up a window. But the result is a page jump. The code looks like this:

after a query and search, it is found that the problem is " return false; " does not work successfully, so there is no default behavior to unlink the link, leaving the visitor out of the current window. If the code is written and its success is communicated, the result is the effect that you want to achieve.

So what's the problem? (see URL: A tag's cancellation default behavior-segmentfaulthttp://segmentfault.com/q/1010000002993720)

Here's a little demo.

Well, the question is how to figure it out, but how to solve it? Online said are said to use Event.preventdefault (); some say more detailed is to distinguish between IE browser and non-IE browser, they block the default behavior has some differences, ie should be window.event.returnValue = = false; Plus Event.stoppropagation (); block bubbling behavior. However...... I tried and tried, and there was no successful implementation of canceling the default behavior.

so, for the time being, I didn't find a way to successfully complete the unlink default behavior while separating the JavaScript, and now it's only possible to write the onclick= in the a tag . "" .

It was a sad ending (╥╯^╰╥)

JavaScript unlink default behavior problem

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.