IE和Firefox浏览器下js css的兼容性分析
?
?
Some functions exist in IE and Firefox, but they might implement different functionality, you can change them into our predefined function in SalIEFirefox.js.
Not compatible:
var wrongGet = obj.firstChild ;
var wrongGet = obj.lastChild ;
var wrongGet = obj.nextSibling ;
var wrongGet = obj.childNodes ;
var wrongGet = obj.previousSibling ;
Compatible
var rightGet = getFirstChild (obj)
var rightGet = getLastChild (obj)
var rightGet = getNextSibling (obj)
var rightGet = getChildNodes (obj)
var rightGet = getPreviousSibling (obj)
Assign a property “id” to HTML element if it miss “id”
Add “id” for every HTML element, because if there is only “name” for HTML element, IE will assign the “name” value to “id”, but Firefox will not.
Not compatible:
tmpHtml.Append("<input type=/"text/" name=/"" + str1 + "/" value=/"0/">" );
Compatible:
tmpHtml.Append("<input type=/"text/" name=/"" + str1 + "/" id=/"" + str1 + "/" value=/"0/">" );
?
It is case-sensitive for HTML element’s id and any parameter in Firefox
Not compatible:
.js var tableDrag= document.getElementById(SectionId+"_dataTable" );
.cs?????? sbdTempHtml.Append("<table id=/"" + SectionId + "_datatable /">" );
Compatible:
.js var tableDrag= document.getElementById(SectionId+"_dataTable" );
.cs?????? sbdTempHtml.Append("<table id=/"" + SectionId + "_dataTable /">" );
?
Don’t use “eval” to cast a string to Object, in other words, using GetElementById(strObjId) instead of eval(strObjId)
Not compatible:
objField1 = eval ("document.mainform.meritid" + i);
Compatible:
objField1 = document.getElementById ("document.mainform.meritid" + i);
?
You should be careful of the following:
Compatible:
var objAjax = eval ("SalaryCom.CompPlanner.CppElementScripts." + document.mainform.aaa.value);
?
Add <tr> between <thead>and<th>, because in IE it will auto add <tr> for it, but Firefox will not. Then when you are trying to get some element using obj.parentNode() might be different.
Not compatible:
sbdTempHtml.Append("<table>" );
sbdTempHtml.Append("<thead>" );
sbdTempHtml.Append("<th width=/"100/">test field name 1</th>" );
sbdTempHtml.Append("<th width=/"200/">test field name 2</th>" );
sbdTempHtml.Append("</thead>" );
sbdTempHtml.Append("<table>" );
Compatible:
sbdTempHtml.Append("<table>" );
sbdTempHtml.Append("<thead>" );
sbdTempHtml.Append("<tr>" );
sbdTempHtml.Append("<th width=/"100/">test field name 1</th>" );
sbdTempHtml.Append("<th width=/"200/">test field name 2</th>" );
sbdTempHtml.Append("</tr>" );
sbdTempHtml.Append("</thead>" );
sbdTempHtml.Append("<table>" );
?
Not compatible:
aRows(i) .cells
Compatible:
aRows[i] .cells
?
Using the following standard way to get/set customized value for HTML element.
?
Not compatible:
var str = Obj.customizedvalue ;
Compatible:
var str = Obj.getAttribute( “ customizedvalue ”) ;
?
Using the following standard way to remove an option in selected element.
Not compatible:
oSel.options.remove (oSel.selectedIndex);
Compatible:
oSel.remove (oSel.selectedIndex);
Firefox doesn’t support Expression in style file.
Not compatible:
top : expression (parentNode.parentNode.parentNode.parentNode.scrollTop) ;
width :expression (document.getElementById('CenterDIV').offsetWidth-16+'px') ;
Compatible:
??????? Consider to use JS method instead of using expression in css.
?
There is no event of onmouseleave() in Firefox, you should change it to onmouseout(),but be careful to change it like following
Not compatible:
div.attachEvent("onmouseleave" ,new Function("clearPopUpMenu();" ));
Compatible:
div.attachEvent("onmouseout" ,new Function("clearPopUpMenu();" ));
?
There is no method obj.fireEvent() in Firefox, you should change it to following:
Not compatible:
div.fireEvent( "onscroll");
Compatible:
fireEvent(div, "onscroll");
?
Firefox doesn’t support this command document.readyState!="complete"
Not compatible:
????????????? if (document.readyState!="complete" )
?
Don’t use window.createPopup() method to create a popup window.
Not compatible:
?????????? window.createPopup();
?
There are some differences between body.scrollLeft and other HTML element(documentElement.scrollLeft), you should care about it.
Not compatible:
var _left = document.body.scrollLeft;
Compatible:
var _left = document.documentElement.scrollLeft;
??????
you should be careful of the following propertys which should be also applied in:
scrollHeight|scrollLeft|scrollTop|scrollWidth
?
A file Cppu_ColorGradient.js can resolve the problem, include the file in Cppb_Header.ascx.cs and do something such as set classname and get client color and so on…
?
Not compatible:
document.GetElementById(strObjId).style.width = 10;
Compatible:
document.GetElementById(strObjId).style.width = ‘10px’;
?
you should be careful of the following propertys which should be also applied in (you can ignore if it is a read only property).
width|height|right|left|scrollHeight|scrollWidth|scrollLeft|scrollTop|offsetHeight|offsetWidth|offsetLeft|offsetTop|clientHeight|clientWidth|clientLeft|clientTop|lineHeight|lineWidth
?
Not compatible:
style=”cursor:hander Compatible:
style=”cursor:pointer ”
?
You should assign “title” and “alt” property for img element. Because it will atuo assign “alt” value to “title” property in IE, while it will not in Firefox.
Not compatible:
sbdTempHtml.Append("<img src=/"../Graphics/i_expand.gif/" /></div>" );
Compatible:
sbdTempHtml.Append("<img alt=/"/" title=/"/" src=/"../Graphics/i_expand.gif/" /></div>" );
?
we are using display:block on tr tag which is not correct in Firefox. After applying display:block, the layout of the table is broken. The default style for tr in Firefox should be ‘display:table-row’
Not compatible:
document.getElementById("hrmtr" ).style.display = "block" ;
Compatible:
if (window.isIE)
document.getElementById("hrmtr" ).style.display = "block" ;
else
document.getElementById("hrmtr" ).style.display = "" ;
?
?
It is only applied in IE if you set opacity as “filter:alpha(opacity=50);”,
Not compatible:
filter :alpha(opacity=50) ;
Compatible:
filter :alpha(opacity=50) ;
-moz-opacity :0.5 ; /*css*/
?
/*The way in js*/
if (!window.isIE)
obj.style.MozOpacity = 0.5;
?
If you want to have browsers IE & FireFox compatible in .css, you should copy a line and prefixed “*”, and the line must be under the original line, then Firefox is hight priority automatically, IE will ignore it and only process a line prefixed “*”.
Not compatible:
margin :10px ;
Compatible:
? margin :20px ; /*for firefox*/
? *margin :10px ; ??? /*for ie7,ie6 */