Web front end compatibility issues summary

Source: Internet
Author: User

1. Getting problems with HTML objects

FireFox:document.getElementById ("Idname");
Ie:document.idname or document.getElementById ("Idname").
Solution: Uniform use of document.getElementById ("Idname");

2. Const ISSUES

Note: Under Firefox, constants can be defined using the Const keyword or the var keyword;
Under IE, you can only use the var keyword to define constants.
Workaround: use the var keyword uniformly to define constants.

3. Event.x and Event.y issues

Description: Under IE, the event object has an X, y attribute but no pagex,pagey attribute;
Under Firefox, the event object has the Pagex,pagey property, but there is no X, Y property.
Workaround: use mx (mx = event.x? Event.x:event.pagex) to replace IE under the Event.x or Firefox under the Event.pagex.

4. WINDOW.LOCATION.HREF Issues

Description: Under IE or firefox2.0.x, you can use window.location or window.location.href;
firefox1.5.x, you can only use window.location.
Workaround: use window.location instead of window.location.href.

5. Frame Issues

Take the following frame as an example:
<frame src= "xxx.html" id= "Frameid" name= "FrameName"/>
(1) To access the Frame object:
IE: Use Window.frameid or window.framename to access the frame object. Frameid and FrameName can have the same name.
Firefox: Only use Window.framename to access this frame object.
In addition, Window.document.getElementById ("Frameid") can be used in both IE and Firefox to access the frame object.
(2) Switch frame content:
You can use Window.document.getElementById ("Testframe") in both IE and Firefox. src = "xxx.html" or window.frameName.location = "xxx.htm L "to toggle the contents of the frame.
If you need to pass the arguments in the frame back to the parent window (note that it is not opener, but the parent frame), you can use parent in the frame to access the parent window. For example: parent.document.form1.filename.value= "aqing";

6. Modal and non-modal window problems

Description: Under IE, the modal and non-modal windows can be opened by ShowModalDialog and showModelessDialog; Firefox is not.
Workaround: open a new window directly using window.open (pageurl,name,parameters).
If you need to pass parameters from a child window back to the parent window, you can use Window.opener in the child window to access the parent window.
For example: var parwin = Window.opener; ParWin.document.getElementById ("aqing"). Value = "aqing";

7. The difference between Firefox and IE's parent element (parentelement)

IE:obj.parentElement
Firefox:obj.parentNode
Workaround: because both Firefox and IE support DOM, using Obj.parentnode is a good choice.

8. Document.formName.item ("ItemName") issues

Problem description: Under IE, you can use Document.formName.item ("ItemName") or document.formname.elements["ElementName"];firefox, Use only document.formname.elements["ElementName"].
Workaround: use document.formname.elements["elementname" uniformly.

9. Collection Class object issues

Problem description: Under IE, you can use () or [] get the Collection class object; Firefox can only use [] to get the collection class object.
Workaround: use [] uniformly to get the collection class object.

10. Custom Attribute Issues

Problem description: Under IE, you can get custom properties by using the method of getting the general properties, or you can use GetAttribute () to obtain the custom attributes, and under Firefox, you can only use getattribute () to derive the custom attributes.
Workaround: Unify through getattribute () to get the custom attributes.

Input.type Property Issues

Problem Description: The Input.type property under IE is read-only, but the Input.type property in Firefox is read-write.
Workaround: do not modify the Input.type property. If you have to modify it, you can hide the original input and then insert a new INPUT element in the same location.

Event.srcelement problems

Problem description: Under IE, even object has Srcelement property, but no target property; Under Firefox, even object has the target property, but there is no srcelement attribute.
Workaround: use srcobj =event.srcelement? event.srcElement:event.target;
If you consider question 8th, use MyEvent instead of event.

Body Loading problem

Problem Description: The body object of Firefox exists before the body tag is fully read by the browser, while the body object of IE must exist after the body tag is fully read into the browser.
[note] This issue has not been verified and will be modified after verification.
[note] proven, IE6, Opera9, and FireFox2 do not have the above problem, the simple JS script can access all the objects and elements that have been loaded before the script, even if this element has not been loaded complete.

14. Event Delegation Method

Problem description: Under IE, use document.body.onload= inject; where Functioninject () has been implemented before, in Firefox, using document.body.onload= inject ();
Workaround: unify the use of document.body.onload=newfunction (' inject () '); or document.body.onload = function () {/* Here is the code */}
Note The difference between function and function.

Table Operation Issues

Problem description: IE, Firefox and other browsers for the table label operation is different, in IE does not allow the table and TR innerHTML assignment, using JS to add a TR, using the AppendChild method is not used.
Workaround://Append a blank line to the table:
var row = Otable.insertrow ( -1), var cell =document.createelement ("TD"), cell.innerhtml = ""; cell.classname = "XXXX"; Row.appendchild (cell); [note] Since I rarely use JS direct operation of the table, this problem has not been met. It is recommended to use the JS frameset to manipulate table, such as jquery.

16. Object width and Height assignment problem

Description: The statement in Firefox similar to Obj.style.height =imgobj.height is invalid.

?        CSS1. Cursor:hand VS Cursor:pointer

Firefox does not support hand, but IE supports pointer
Workaround: use pointer uniformly

2. innertext works in IE, but not in Firefox.

Need textcontent.
Workaround:
if (Navigator.appName.indexOf ("explorer") >-1) {
document.getElementById (' element '). InnerText = "my text";
} else{
document.getElementById (' element '). Textcontent = "my text";
}

3. CSS Transparency

IE:filter:progid:DXImageTransform.Microsoft.Alpha (style=0,opacity=60).
ff:opacity:0.6.

4. Width and padding in CSS

Width widths in IE7 and FF do not include padding, and padding are included in Ie6.

5. FF and Iebox models explain inconsistencies resulting in a 2px difference

box.style{width:100;border1px;}
ie understood as Box.width =100
FF understood as Box.width = 100 + 1*2 = 102//plus Border 2px

Workaround:div{margin:30px!important;margin:28px;}
Note that the order of the two margin must not be written counter, IE does not recognize!important this attribute, but other browsers can be recognized. So under IE actually explains this: div{maring:30px;margin:28px}
Repeat definition is executed according to the last one, so it is not possible to write only margin:xxpx!important;

6. IE5 and IE6 's box explanations are inconsistent

IE5 under div{width:300px;margin:0 10px 0 10px;}
The width of the div is interpreted as 300px-10px (right padding) -10px (left padding), the final div width is 280px, and the width on IE6 and other browsers is calculated as 300px+10px (right padding) +10px (left padding) =320px. At this point we can make the following changes Div{width:300px!important;width/**/:340px;margin:0 10px 0 10px}

7. UL and OL list indent issues

Eliminate the UL, OL and other list of indentation, the style should be written as: list-style:none;margin:0px;padding:0px;
It is verified that in IE, setting margin:0px can remove the upper and lower left and right indent, blank and list number or dot of list, setting padding has no effect on style; in Firefox, setting margin:0px can only remove upper and lower whitespace, set padding:0 Only the left and right indents can be removed after PX, and List-style:none must be set to remove the list number or dot. In other words, in IE, only set margin:0px can achieve the final effect, and in Firefox must be set margin:0px, padding:0px and list-style:none three items to achieve the final effect.

8. Element horizontal Centering Problem

Ff:margin:0auto;

IE: Parent {text-align:center;}

9. Vertical center of DIV problem

Vertical-align:middle; Increase the line spacing as high as the entire DIV: line-height:200px, then insert the text and center vertically. The disadvantage is to control the content not to wrap.

10. margin double the problem

A div set to float doubles the margin set under IE. This is a bug that exists in a IE6. The solution is to add display:inline to this div;

For example:

<divid= "Imfloat" >
The corresponding CSS is
#imfloat {
Float:left;
Margin:5px;/*ie understood as 10px*/
Display:inline;/*ie under the 5px*/}

A. ie with width and height issues

IE does not recognize the definition of min-, but in fact it treats the normal width and height as a condition of min. This problem is big, if only with the width and height, the normal browser of these two values will not change, if only with Min-width and min-height, ie, the following is not set width and height.

For example, to set the background image, this width is more important. To solve this problem, you can:

#box {width:80px; height:35px;} Html>body #box {width:auto;height:auto; min-width:80px; min-height:35px;}

12. Minimum width of the page

As the previous problem, IE does not recognize min, to achieve the minimum width, the following methods can be used:

#container {min-width:600px;width:expression (document.body.clientwidth< 600?) "600px": "Auto");}

The first min-width is normal, but the width of line 2nd uses JavaScript, which only IE recognizes, which also makes your HTML document less formal. It actually achieves the minimum width by JavaScript's judgment.

Div floating IE text generates 3 pixel bug

The left object floats, the right side is positioned with the left margin of the outer patch, and the text within the right object is spaced 3px away from the left.

#box {float:left; width:800px;}
#left {float:left; width:50%;}
#right {width:50%;}
*html #left {margin-right:-3px;//This sentence is the key}
<div id= "box" >
<div id= "left" ><div id= "right" ></div>

The problem of IE hide and seek

When the div application is complex, there are some links in each column, and the div is prone to hide-and-seek problems.

Some content does not show up when the mouse selects this area is found content is indeed on the page.

WORKAROUND: Use Line-height attribute for #layout or use fixed height and width for #layout. The page structure is as simple as possible.

The div closure of the. float; clear float; Adaptive height

Example:

The NOTFLOATC here do not want to continue panning, but want to go down the line. (where the properties of Floata and FLOATB have been set to float:left;)

This code is no problem in IE, the problem is in FF. The reason is that NOTFLOATC is not a float label and the float label must be closed. In

this div must pay attention to the location, and There must be no nesting relationship with two Div siblings with the float attribute , or an exception will occur. And the clear style is defined as follows: . Clear{clear:both;}

as an external wrapper div do not set dead height, in order to allow the height of self-adaptation , to wrapper inside add Overflow:hidden; When the box containing float, the height of adaptive under IE invalid, this time should trigger the layout of IE private property (Evil ie Ah!). ) with zoom:1; Can be done so that the compatibility is achieved.
For example a certain wrapper is defined as follows:

. Colwrapper{overflow:hidden; zoom:1; margin:5px Auto;}

for typography, the CSS description we use most probably is float:left. Sometimes we need to do a uniform background behind the float div in the n column, for example:

<div id= "Page" >

<div id= "left" ><div id= "center" ><div id= "right" >

</div>

For example, we want to set the page's background to blue, to achieve all three columns of the background color is blue, but we will find that with the left centerright is stretched downward, and page incredibly save the height of the same, the problem is because the page is not a float property, And our page is to be centered, cannot be set to float, so we should solve this:

<div id= "Page" >

<div id= "bg" style= "float:left;width:100%" >

<div id= "left" ><div id= "center" ><div id= "right" >

</div>

</div>

Then embed a float left and the width is 100% div resolved.

④ Universal float closed (very important!)

For the principle of clear float see [How to Clearfloats without Structural Markup], add the following code to the global CSS, add class= "Clearfix" to the div that needs to be closed, try Upset.

/* Clear Fix */
. clearfix:after {content: "."; display:block; height:0; clear:both;visibility:hidden;}
. clearfix {Display:inline-block;}
/* Hide from IE MAC */
. clearfix {Display:block;}
/* End Hide from IE Mac */
/* End of Clearfix */

Alternatively, set:. hackbox{display:table;//Display the object as a block-element-level table}

16. Highly non-adaptable

Height intolerance is when the height of the inner object changes, the outer height cannot be automatically adjusted, especially when the inner object uses margin or padding.

Cases:

#box {}
#box p {margin-top:20px;margin-bottom:20px; text-align:center;}
<div id= "box" >
The contents of the <p>p object </div>

Workaround: Add 2 empty div object CSS code {Height:0px;overflow:hidden;} to the P object. Or add the border attribute to the Div.

17. IE6 There are voids in the film .

There are many tricks to fix this bug, either to change the layout of the HTML, or to set the IMG to Display:block or set the Vertical-align property to vertical-align:top/bottom/middle/ Text-bottom can all be solved.

18. Text input Box

Plus vertical-align:middle;

<style type= "Text/css" >
<!--
Input {
width:200px;
height:30px;
border:1px solid red;
Vertical-align:middle;
}
-
</style>

Verified that the next version of IE is not applicable, and FF, Opera, Safari, Chrome are all ok!

When content in Li exceeds length, it is displayed as an ellipsis

This technique works with IE, Opera, Safari, Chrom Browser, FF temporarily not supported.

<style type= "Text/css" >
<!--
Li {
width:200px;
White-space:nowrap;
Text-overflow:ellipsis;
-o-text-overflow:ellipsis;
Overflow:hidden;
}

-
</style>

20. Why IE Cannot set scroll bar color in Web Standard

The solution is to replace body with HTML

<! doctypehtml Public "-//w3c//dtd XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312"/>
<style type= "Text/css" >
<!--
HTML {
Scrollbar-face-color: #f6f6f6;
Scrollbar-highlight-color: #fff;
Scrollbar-shadow-color: #eeeeee;
Scrollbar-3dlight-color: #eeeeee;
Scrollbar-arrow-color: #000;
Scrollbar-track-color: #fff;
Scrollbar-darkshadow-color: #fff;
}
-

21. Why can't I define a container with around 1px height?

IE6 This problem is due to the default row height, there are a number of techniques to solve:

Example: Overflow:hidden zoom:0.08 line-height:1px

16. How can I make the layer appear above flash?

The workaround is to set the flash to transparent

<paramname= "wmode" value= "Transparent"/>

22. Link (A-label) border and background

A link with border and background color, need to set Display:block, and set Float:left guarantee not wrap. Refer to MenuBar, set a and menubar height is to avoid the bottom of the display dislocation, if not set height, you can insert a space in the menubar.

23. Hover style does not appear after hyperlink access

The clicked Hyperlink style is not hover and active, many people should have encountered this problem, the solution is to change the order of CSS properties: l-v-h-a

Code:

<style type= "Text/css" >
<!--
A:link {}
a:visited {}
a:hover {}
a:active {}
-
</style>

Form label

This tag in IE, will automatically margin some margins, and in the FF margin is 0, so if you want to show consistency, so it is best to specify the margin and padding in the CSS, for the above two issues, my CSS is generally used first in the style Ul,form {margin:0;padding:0;}.

25. Attribute selector (this is not compatible, is a bug to hide CSS)

p[id]{}div[id]{}

This is hidden for IE6.0 and IE6.0 versions, FF and opera. There is a difference between the property selector and the child selector, the range of the sub-selector is reduced in form, the range of the property selector is larger, such as P[id], and all P tags have the same type of ID.

26. Why the text in FF cannot open the height of the container

The container of fixed height value in standard browser is not open like IE6, then I want to fixed height, and want to be able to be open how to set it? The way is to remove height setting min-height:200px; Here in order to take care of the IE6 do not know min-height can be defined as:

{
Height:auto!important;
height:200px;
min-height:200px;
}

Web front end compatibility issues summary

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.