Differences between JavaScript and IE and Firefox and Their Solutions)

Source: Internet
Author: User
Tags xsl

Differences and solutions between Javascript in IE and Firefox

1. load XML
IE creation object:
Msxmlax = new activexobject ("Microsoft. xmldom ");
Firefox creation object:
Xdoc = Document. Implementation. createdocument ("", "", null );

The general method is:
/// Determine whether the browser creates different objects
Function getxmldocument ()
{
VaR xdoc;
If (document. Implementation & document. Implementation. createdocument)
{
Xdoc = Document. Implementation. createdocument ("", "", null );
}
Else if (typeof activexobject! = "Undefined ")
{
VaR msxmlax = NULL;
Try {
Msxmlax = new activexobject ("Microsoft. xmldom ");
}
Catch (E)
{

Msxmlax = new activexobject ("Microsoft. xmldom ");
}
Xdoc = msxmlax;

}
If (xdoc = NULL | typeof xdoc. load = "undefined ")
{
Xdoc = NULL;


}
Return xdoc;

}

2. insertrow and insertcell
In IE, you can directly call this method document. getelementbyid ("XXX"). insertrow ();
In Firefox, You need to place the parameter document. getelementbyid ("XXX"). insertrow (-1 );

Similarly, insertrow (-1) also supports IE

3. Determine the browser type

/*---------------------------------------------------------------
-- This function can return the actual browser name and version .--
-- Usesage: There are two methods (see the end of this function )--
-- Create by yemoo. datetime: 2006-2-3 21:53:37 --
---------------------------------------------------------------*/
Function browserinfo (){
VaR browser_name = navigator. appname;
VaR browser_version = parsefloat (navigator. appversion );
VaR browser_agent = navigator. useragent;

VaR actual_version, actual_name;

VaR is_ie = (browser_name = "Microsoft Internet Explorer ");
VaR is_nn = (browser_name = "Netscape ");

If (is_nn ){
// Upper 5.0 need to be process, lower 5.0 return directly
If (browser_version> = 5.0 ){
VaR split_sign = browser_agent.lastindexof ("/");
VaR version = browser_agent.indexof ("", split_sign );
VaR bname = browser_agent.lastindexof ("", split_sign );

Actual_version = browser_agent.substring (split_sign + 1, version );
Actual_name = browser_agent.substring (bname + 1, split_sign );
}
Else {
Actual_version = browser_version;
Actual_name = browser_name;
}
}
Else if (is_ie ){
VaR version_start = browser_agent.indexof ("MSIE ");
VaR version_end = browser_agent.indexof (";", version_start );
Actual_version = browser_agent.substring (version_start + 5, version_end)
Actual_name = browser_name;

If (browser_agent.indexof ("Maxthon ")! =-1 ){
Actual_name + = "(Maxthon )";
}
Else if (browser_agent.indexof ("Opera ")! =-1 ){
Actual_name = "Opera ";
VaR tempstart = browser_agent.indexof ("Opera ");
VaR tempend = browser_agent.length;
Actual_version = browser_agent.substring (tempstart + 6, tempend)
}
}
Else {
Actual_name = "unknown Navigator"
Actual_version = "unknown version"
}
/*------------------------------------------------------------------------------
-- Your can create new properties of Navigator (acutal_name and actual_version )--
-- Userage :--
-- 1, call this function .--
-- 2, use the property like this: navigator. actual_name/navigator. actual_version ;--
------------------------------------------------------------------------------*/
Navigator. actual_name = actual_name;
Navigator. actual_version = actual_version;

/*---------------------------------------------------------------------------
-- Or made this a class .--
-- Userage :--
-- 1, create a instance of this object like this: var browser = new browserinfo ;--
-- 2, user this instance: browser. Version/browser. Name ;--
---------------------------------------------------------------------------*/
This. Name = actual_name;
This. Version = actual_version;
}
Use navigator. actual_name to get the browser name. Use navigator. actual_version to get the browser version.

4. In Firefox, you cannot obtain information about all elements of an XML text object through documentelement like ie. You can use the replacement method:
Create an XMLHTTPRequest object and operate it through the XML object returned by its responsexml

5. Windows. event is not supported in Firefox.
Solution:
Document. onclick = function (e) // to be compatible with FF, write this parameter
{
E = Window. Event | E;
E = E. srcelement | e.tar get;
// Other implementation code
}
6. Firefox does not support parentelement. to use it, you can write it as parentnode.

7. When XML is formatted using XSL in IE, use the following code:
Xmldoc. transformnode (invalid DOC );
Xmldoc is an XML document.
The release Doc is an XSL document.
Use the following code in Firefox:
VaR effectprocessor = new effectprocessor ();
Effectprocessor. importstylesheet (invalid DOC );
VaR resulthtml = effectprocessor. transformtodocument (xmldoc );
VaR oxmlserializer = new xmlserializer ();
$ Getele ("zfdiv _"). innerhtml = oxmlserializer. serializetostring (resulthtml );

8. In ifream loading, the height of the IFRAME changes according to the height of the loaded page.
The Code on the internet is:
<IFRAME onload = "document.all.demo.height?document.frames='demo'}.doc ument. Body. scrollheight" src = "demo.htm"/>
The code is fine, but the desired effect cannot be achieved in Firefox.
Changed:
Document.getelementbyid('demo'demo.height?##frames='demo'}.doc ument. Body. scrollheight
You can.

Related Article

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.