Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of event event handling in firefox

Shulou Source: shulou.com Published: 2022-06-03 14:24:21 09月28日 Update

This article is about an example analysis of event handling in firefox. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

When angularJs is used to implement a function, click to obtain the x and y coordinates of the event, the function is normal under IE9, chrome. Firefox event is undefined. The initial code is as follows:

html:

addRes

js:

$scope.addResPop = function () { var x = window.event.screenX;//ff Report undefined .... }

As a result, the console reported an error after clicking ff. After checking the data, we know that the differences of browser event objects are as follows:

1. In IE, event can be used as an attribute of window object directly.

In the W3 standard,event objects must be passed as parameters to event handlers, provided that they are used in our code. So, to access event objects in standard compatible browsers (Mozilla,Safari,Opera), do this:

addRes $scope.addResPop = function($event) { .... }

Note that angular $event is used here, which blocks browser compatibility issues for developers. It uses jQuery to bind click event, and the result of obtaining event object is exactly the same as $event obtained by angular, for example:

$("body").click(function(event){ ...... })

Understand browser compatibility issues and use the Tripartite Library to shield common compatibility issues.

Thank you for reading! About "firefox event handling example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that we can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Events objects browsers browsing processing problems examples analysis code content functions more standards articles results good practical tripartite functions premises Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn macOS Redmi MariaDB