Home > Web Front-end > JS Tutorial > How to Prevent Form Submission in Internet Explorer?

How to Prevent Form Submission in Internet Explorer?

Linda Hamilton
Release: 2024-11-30 04:46:10
Original
1068 people have browsed it

How to Prevent Form Submission in Internet Explorer?

Preventing Form Submission in IE: Overcoming the event.preventDefault() Limitation

As an extension of the event.preventDefault() function, this article delves into the issue of its lack of support in Internet Explorer.

The original code provided demonstrates a form validation process using JavaScript's Mootools library. In browsers other than IE, the event.preventDefault() method effectively prevents the form from submitting prematurely. However, in IE, an error arises due to the absence of this method.

To resolve this issue, IE offers an alternative approach:

event.returnValue = false;
Copy after login

This line can be seamlessly implemented to achieve the same result as event.preventDefault().

To enhance error handling, a quick check can be performed to determine the availability of event.preventDefault():

if(event.preventDefault) event.preventDefault();
Copy after login

By combining both approaches, the following code ensures compatibility across all major browsers:

event.preventDefault ? event.preventDefault() : (event.returnValue = false);
Copy after login

The above is the detailed content of How to Prevent Form Submission in Internet Explorer?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template