JS browser differences (ie and ff)

Source: Internet
Author: User

1. Disable Div selection:
$ (Dataid). BIND ("selectstart", function () {// ie disable Div Selection
Return false;

}
Optional (dataid).css ("-moz-user-select", "NONE"); // FF disable Div Selection

2. Window. Close () (all windows opened through window. Open can be closed)

Firefox uses JavaScript: window. Close () to close a click link or a new window. It cannot close a window opened by entering the address bar;

Ie can be disabled directly

3. Event source srcelement and target

VaR elemente.tar GET | E. srcelement; // e.srcelementis under IE, and e.tar get is under FF

4. offset ()

When using the offset () method to set coordinates, it is best to set the top and left attributes of CSS in IE, otherwise the wrong coordinates will be generated.

For example

<! Doctype HTML public "-// W3C // dtd html 4.01 // en" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<SCRIPT type = "text/JavaScript" src = "lib/jquery/jquery-1.4.2.js"> </SCRIPT>
<Title> untitled document </title>
<SCRIPT type = "text/JavaScript">
$ (Function ()
{
$ ("# Aa"). offset ({top: 0, left: 0 });
Alert ($ ("# Aa"). offset (). Top); // here it is inexplicably 92
$ ("# AABC"). Click (function ()
{
$ ("# Aa"). offset ({top: 0, left: 0 });
})
});
</SCRIPT>
<Style type = "text/CSS">
# Bb
{
Top: 20px;
}
# Aa
{
Top: 30px; // No attribute is set.-92 is displayed on the top, and the value is 0. It is better to set the top and left attributes first. Otherwise, unexpected results will be generated.
Position: absolute;
}
</Style>
</Head>
<Body>
<Div style = "height: 60px;" id = "BB" style = "Top: 10px;"> </div>
<Input type = "button" value = "test" id = "AABC"/>
<! -- Template HTML -->
<Div id = "AA">
Aaaaaa </BR>
Bbbbbb </BR>
Cccccc </BR>
</Div>
</Body>
</Html>

 

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.