Home > Web Front-end > JS Tutorial > Various browser compatibility issues_Basic knowledge

Various browser compatibility issues_Basic knowledge

WBOY
Release: 2016-05-16 19:24:15
Original
1148 people have browsed it
About setting onload event handle with script

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

It works fine in IE and Opera Effective, except that FF neither executes nor reports an error, because in FF, document.body.onload is undefined (undefined), and nothing will happen if a function is assigned to undefined, nor is it an error.
This is valid in IE, Opera and FF:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
About using scripts Bind event handle

Use attachEvent under IE, and use addEventListener under FF
The relevant discussion is as follows:
http://search.blueidea.com/?q=addEventListener&bisearch= bbs

(You can basically understand it after reading a few posts, so I won’t go into details. Please don’t comment on old posts when reading, thank you)
Reference link:
http://bbs.blueidea.com/viewthre ... p;page=1#pid2248824
http://bbs.blueidea.com/viewthread.php?tid=2507914
About floating codes and documentElement / body

People often ask why floating ads / couplet codes cannot be used under xHTML 1.1 DTD file header / FF
This is because, according to the standard For example, the scroll bars of the form we see should not be of body, but of HTML (that is, document.documentElement object)So, the solution is to put the previously non-standard code into document.body .scrollTop or similar code is transformed into document.documentElement.scrollTop
Regarding the reference of ID and html object elements
There are many reasons for this problem. But a basic prerequisite is that for IE, the ID of an HTML element can be used directly as a variable name in a script, but not in FF. Copy code
The code is as follows:

Copy code
The code is as follows:



About the differences in the use of event objects
In IE, when an event is triggered, there is a global window.event object that saves event-related information
IE Only
[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute <script> document.body.onload=function(){alert("!")} </script>]<script> window.onload=function(){alert("!")} </script>
FF 中,事件激发的时候,将一个局部的 event 对象作为第一个参数传递给了事件处理函数
FF Only

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

此外,IE 的 event 对象和 FF 的 event 对象还稍有不同。
以下是我常用的兼容形式

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

参考
http://bbs.blueidea.com/thread-2667939-1-1.html
Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template