


Details of firefox and ie event processing, research, and further research. Writing event processing code that is compatible with both ie and ff_javascript skills
In IE, the event object is saved and maintained as a global variable. All browser events, whether triggered by the user or other events, will update the window.event object. So in the code, you can easily get the event object by simply calling window.event, and then use event.srcElement to get the element that triggered the event for further processing. In ff, the event object is not a global object. Generally, it happens on-site. , used on site, ff automatically passes the event object to the corresponding event processing function. In the code, the first parameter of the function is the event object under ff.
The above is my personal understanding of the event processing methods under the two browsers. It may not be very clear. I wrote some code to
explain it in detail
<script> <br>window.onload=function(){ <br>document.getElementById("btn1").onclick=foo1 <br>document.getElementById("btn2").onclick=foo2 <br>document.getElementById("btn3").onclick=foo3 <br>} <br>function foo1(){ <br>//In ie, window.event makes the global object <br>alert(window.event) // Under ie, "[object]" is displayed, and under ff, "undefined" is displayed <br> //In ff, the first parameter automatically changes from the event object <br>alert(arguments[0]) // Under ie, it displays "undefined", under ff, it displays "[object]" <br>} <br>function foo2(e){ <br>alert(window.event) // Under ie, "[object]" is displayed, and under ff, "undefined" is displayed <br>//Note, I have never passed parameters to foo2. Now ff automatically passes parameters to foo2, and the passed parameter e is the event object <br>alert(e) // Under ie, "undefined" is displayed, and under ff, "[object]" is displayed <br>} <br>function foo3 (){ //Compatible with both ie and ff writing methods, take the event object <br>alert(arguments[0] || window.event) // Under both ie and ff, "[object]" is displayed <br>var evt =arguments[0] || window.event <br>var element=evt.srcElement || evt.target //Get btn3 object under ie and ff <br>alert(element.id) // btn3 <br>} <br></script>
Seeing this, we seem to have understood the event handling methods of ie and ff, and have found a solution.
But. . . . It's not over yet.
Look at the code
<script> <br>function foo(){ <br>alert(arguments[0] || window.event) <br>} <br></script>
Unfortunately, the result foo gives us is undefined, not the expected object
The reason is the way the event is bound
onclick=" foo()" is executed directly. The foo() function does not have any parameters.
In this case, firefox has no chance to pass any parameters to foo
In this case, btn.onclick=foo, because it is not directly Only after executing the function does firefox have the opportunity to pass parameters to foo
Solution:
Method 1: A stupid method. Since firefox has no chance to pass parameters, be diligent and pass them yourself
Method 2: Automatic search
<script> <br>function foo4(){ <br>var evt=getEvent() <br>var element=evt.srcElement || evt.target <br> alert(element.id) <br>} <br>function getEvent(){ //compatible with both ie and ff writing <br>if(document.all) return window.event; <br>func=getEvent.caller; <br>while(func!=null){ <br>var arg0=func.arguments[0]; <br>if(arg0){ <br>if((arg0.constructor==Event || arg0.constructor = =MouseEvent) <br>|| (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){ <br>return arg0; <br>} <br>} <br>func=func. caller; <br>} <br>return null; <br>} <br></script>
Method 2 was originally created by lostinet, and I have improved on it. The original function is as follows:
var arg0=func.arguments[0];
if(arg0)
{
if(arg0.constructor==Event)
return arg0;
}
func=func.caller;
}
return null;
}
Simple summary:
Both of the above In the solution, event processing under ff and ie is correctly handled (whether it is onclick="foo()" or onclick=foo)
But I personally recommend using the getEvent() method to handle event issues uniformly.
That’s it for now, let’s continue. .

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To remove FirefoxSnap in Ubuntu Linux, you can follow these steps: Open a terminal and log in to your Ubuntu system as administrator. Run the following command to uninstall FirefoxSnap: sudosnapremovefirefox You will be prompted for your administrator password. Enter your password and press Enter to confirm. Wait for command execution to complete. Once completed, FirefoxSnap will be completely removed. Note that this will remove versions of Firefox installed via the Snap package manager. If you installed another version of Firefox through other means (such as the APT package manager), you will not be affected. Go through the above steps

A brief introduction to python GUI programming GUI (Graphical User Interface, graphical user interface) is a way that allows users to interact with computers graphically. GUI programming refers to the use of programming languages to create graphical user interfaces. Python is a popular programming language that provides a rich GUI library, making Python GUI programming very simple. Introduction to Python GUI library There are many GUI libraries in Python, the most commonly used of which are: Tkinter: Tkinter is the GUI library that comes with the Python standard library. It is simple and easy to use, but has limited functions. PyQt: PyQt is a cross-platform GUI library with powerful functions.

It's no secret that Internet Explorer has fallen out of favor for a long time, but with the arrival of Windows 11, reality sets in. Rather than sometimes replacing IE in the future, Edge is now the default browser in Microsoft's latest operating system. For now, you can still enable Internet Explorer in Windows 11. However, IE11 (the latest version) already has an official retirement date, which is June 15, 2022, and the clock is ticking. With this in mind, you may have noticed that Internet Explorer sometimes opens Edge, and you may not like it. So why is this happening? exist

Introduction CircularQueue is an improvement on linear queues, which was introduced to solve the problem of memory waste in linear queues. Circular queues use the FIFO principle to insert and delete elements from it. In this tutorial, we will discuss the operation of a circular queue and how to manage it. What is a circular queue? Circular queue is another type of queue in data structure where the front end and back end are connected to each other. It is also known as circular buffer. It operates similarly to a linear queue, so why do we need to introduce a new queue in the data structure? When using a linear queue, when the queue reaches its maximum limit, there may be some memory space before the tail pointer. This results in memory loss, and a good algorithm should be able to make full use of resources. In order to solve the waste of memory

More and more users are starting to upgrade the win11 system. Since each user has different usage habits, many users are still using the ie11 browser. So what should I do if the win11 system cannot use the ie browser? Does windows11 still support ie11? Let’s take a look at the solution. Solution to the problem that win11 cannot use the ie11 browser 1. First, right-click the start menu and select "Command Prompt (Administrator)" to open it. 2. After opening, directly enter "Netshwinsockreset" and press Enter to confirm. 3. After confirmation, enter "netshadvfirewallreset&rdqu

Mozilla Firefox can be uninstalled; Firefox is a third-party browser and can be uninstalled if it is not needed. Uninstallation method: 1. In the Start menu, click "Windwos System" - "Control Panel"; 2. In the "Control Panel" interface, click "Programs and Features"; 3. In the new interface, find and double-click Firefox Browser icon; 4. In the uninstall pop-up window, click "Next"; 5. Click "Uninstall".

Recently, many win10 users have found that their IE browser always automatically jumps to the edge browser when using computer browsers. So how to turn off the automatic jump to edge when opening IE in win10? Let this site carefully introduce to users how to automatically jump to edge and close when opening IE in win10. 1. We log in to the edge browser, click... in the upper right corner, and look for the drop-down settings option. 2. After we enter the settings, click Default Browser in the left column. 3. Finally, in the compatibility, we check the box to not allow the website to be reloaded in IE mode and restart the IE browser.

Event processing library in PHP8.0: Event With the continuous development of the Internet, PHP, as a popular back-end programming language, is widely used in the development of various Web applications. In this process, the event-driven mechanism has become a very important part. The event processing library Event in PHP8.0 will provide us with a more efficient and flexible event processing method. What is event handling? Event handling is a very important concept in the development of web applications. Events can be any kind of user row
