您的位置:新葡亰496net > 服务器网络 > 摘自启点的main,在javascript中操作兼容IE

摘自启点的main,在javascript中操作兼容IE

发布时间:2019-12-01 01:30编辑:服务器网络浏览(102)

    复制代码 代码如下:functionCLASS_AUTOUPDATE { this.instanceName=instanceName; this.updating=false; this.error=false; this.updateInfo=""; this.nextVersion=""; this.ver=""; this.win=win; this.updatePath=""; this.updateFileName=""; this.softName=""; this.refresh(); } CLASS_AUTOUPDATE.prototype.onafterupdate=function() { var_window=this.win; vartempMessageWidth=360; vartempMessageHeight=160; vartempMessageLeft=(document.body.clientWidth-tempMessageWidth卡塔尔国/2; vartempMessageTop=(document.body.clientHeight-tempMessageHeight卡塔尔(英语:State of Qatar)/2; varfeature={ title:"更新实现", width:tempMessageWidth, height:tempMessageHeight, left:tempMessageLeft, top:tempMessageTop, borderColor:"#8B89A1", backgroundColor:"#FFFFFF", color:"#000000", titleBackgroundColor:"#8B89A1", titleColor:"#FFFFFF", dragable:true }; varTHIS=this; vartempMessageContent=[]; //tempMessageContent[tempMessageContent.length]=""; tempMessageContent[tempMessageContent.length]=this.updateInfo; //tempMessageContent[tempMessageContent.length]="

    String.prototype.trim = function()
    {
        return this.replace(/(^s*)|(s*$)/g, "");
    }

        一聊起XMLDOM在IE/Firefox浏览器的包容性,平素都以头疼的难题,也苦了众多前辈在多行业内部的现状下计算出了颇负价值的代码,避防后人再走弯路。随着javascript和dom版本的四处晋升,旧的代码在成效和达成上也适合时宜的现身些变化,达到适应最新同一时候向下包容的效果。在javascript中操作xmldom常用的有以下两种情景:

            异步调用的标题是一应俱全,说碰上就冲击,此番本人凌驾的难为正是那般,肖似的异步央求,在IE6SP1中运作一点标题绝非,在IE6SP第22中学只成功实行三回后,每一趟的结果都和第贰次相仿,随后又尝试IE7和Firefox,效果和IE6SP2相像,用Fiddler监视明明来得正确的诉求和重回值,可就算最终实行的效果与利益一点都没变化,卓绝忧愁。那样的结果自然就想开了料定是缓存在作怪,但始终依旧要查明到底是哪段代码引起缓存的,作者把关注的刀口放在如下代码:
    var xmlHttp = null;
    function getXmlHttp(){
        if(window.XMLHttpRequest){
            xmlHttp = new XMLHttpRequest();
        }else if(window.ActiveXObject){
            var arrXmlHttpTypes = ['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'];
            for(var i=0;i<arrXmlHttpTypes.length;i ){
                try{
                    xmlHttp = new ActiveXObject(arrXmlHttpTypes[i]);
                }catch(ex){}
            }
        }
    }

    "; tempMessageContent[tempMessageContent.length]=""; tempMessageContent[tempMessageContent.length]=""; _window.open; _window.write("updateOk",tempMessageContent.join; _window.items["updateOk"].all.onclick=function() { _window.close; } _window.items["updateOk"].onunload=function() { if(THIS.error==false&&THIS.updateFileList.length>0) { document.location.reload(); } } } CLASS_AUTOUPDATE.prototype.check=function() { var_current_version,_new_version,_exist_new_ver; //检查安插文件 varconfigXML=newCLASS_XML("xml\autoupdate.xml"); if(configXML.error==false) { var_update_date,_autoupdate_day,_current_version; var_save_or_not; var_d=newDate(); var_dd=_d.getFullYear 1) "-" _d.getDate(卡塔尔国; //检查是还是不是有创新时间段设置 if(configXML.selectSingleNode==null卡塔尔(英语:State of Qatar) { configXML.setText("/Config","UpdateDate",_dd); _update_date=_dd; _save_or_not=true; } else { _update_date=configXML.getText("/Config","UpdateDate","1900-01-01"); } if(configXML.selectSingleNode("/Config/AutoUpdateDay")==null) { configXML.setText("/Config","AutoUpdateDay","10"); _autoupdate_day="10"; _save_or_not=true; } else { _autoupdate_day=configXML.getText("/Config","AutoUpdateDay","10"); } _autoupdate_day=_autoupdate_day*1; if(configXML.selectSingleNode("/Config/CurrentVersion")==null) { configXML.setText("/Config","CurrentVersion","0.32"); _current_version="0.32"; _save_or_not=true; } else { _current_version=configXML.getText("/Config","CurrentVersion","0.32"); } _current_version=_current_摘自启点的main,在javascript中操作兼容IE。version*1; //决断是不是前日去老是服务器 var_od=newDate(_update_date.replace; if-_od.getTime()>_autoupdate_day*24*3600*1000) { varnewDoc=newCLASS_XML(); newDoc.loadRemoteFile(this.updatePath this.softName "/" this.updateFileName); if(newDoc.selectSingleNode("/Config/CurrentVersion")==null) { newDoc.setText("/Config","CurrentVersion","0.32"); _new_version="0.32"; } else { _new_version=newDoc.getText("/Config","CurrentVersion","0.32"); } _new_version=_new_version*1; //检查是或不是有新本子 if(_new_version>_current_version) { _exist_new_ver=true; } configXML.setText("/Config","UpdateDate",_dd); _save_or_not=true; } if { configXML.save(); } } if { var_window=this.win; vartempMessageWidth=260; vartempMessageHeight=120; vartempMessageLeft=(document.body.clientWidth-tempMessageWidth)/2; vartempMessageTop=(document.body.clientHeight-tempMessageHeight)/2; varfeature={ title:"升级", width:tempMessageWidth, height:tempMessageHeight, left:tempMessageLeft, top:tempMessageTop, borderColor:"#8B89A1", backgroundColor:"#FFFFFF", color:"#000000", titleBackgroundColor:"#8B89A1", titleColor:"#FFFFFF", dragable:true }; varTHIS=this; vartempMessageContent=[]; //tempMessageContent[tempMessageContent.length]=""; tempMessageContent[tempMessageContent.length]="

    String.prototype.len=function()
    {
        return this.replace(/[^x00-xff]/g,'aa').length;

        一、创建XMLDOM对象

    function getXmlDom(content){
        var _xmlDom = null;
        if (!window.DOMParser  && window.ActiveXObject){
            var arrXmlDomTypes = ['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];
            for(var i=0;i<arrXmlDomTypes.length;i ){
                try{
                    _xmlDom = new ActiveXObject(arrXmlDomTypes[i]);
                    _xmlDom.async = false;
                    _xmlDom.loadXML(content);
    //                _xmlDom.setProperty('SelectionLanguage', 'XPath');
                }catch(ex){}
            }
        }else{
                try{
                    var domParser = new window.DOMParser();
                    _xmlDom =  domParser.parseFromString(content, 'text/xml');
                    Element.prototype.selectSingleNode=function(sXPath){
                        var oEvaluator = new XPathEvaluator();
                        var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.FIRST_ORDERED_NODE_TYPE,null);
                        if(null != oResult){
                            return oResult.singleNodeValue;
                        }
                        return null;
                    }
                   
                    Element.prototype.selectNodes = function(sXPath){
                        var oEvaluator = new XPathEvaluator();
                        var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
                        var aNodes = new Array();
                        if(null != oResult){
                            var oElement = oResult.iterateNext();
                            while(oElement){
                                aNodes.push(oElement);
                                oElement = oResult.iterateNext();
                            }
                        }
                        return aNodes;
                    }
                   
    新葡亰496net,                Element.prototype.__defineGetter__("text",function(){ return this.textContent; });        }
            catch (ex)
            {
               
            }
        }
        return _xmlDom;
    }              

    有新本子,是还是不是更新?

    function StringBuilder(value)
    {
        this.strings = new Array("");
        this.append(value);
    }

     1新葡亰496net 1var _xmlDom = null;
     2新葡亰496net 2新葡亰496net 3    if (!window.DOMParser  && window.ActiveXObject)新葡亰496net 4{
     3新葡亰496net 5        var arrXmlDomTypes = ['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];
     4新葡亰496net 6新葡亰496net 7        for(var i = 0;i<arrXmlDomTypes.length;i )新葡亰496net 8{
     5新葡亰496net 9新葡亰496net 10            try新葡亰496net 11{
     6新葡亰496net 12                _xmlDom = new ActiveXObject(arrXmlDomTypes[i]);
     7新葡亰496net 13新葡亰496net 14            }catch(ex)新葡亰496net 15{}//不支持MSXML.XMLDOM对象的IE
     8新葡亰496net 16        }
     9新葡亰496net 17新葡亰496net 18    }else新葡亰496net 19{// Mozilla browsers have a DOMParser
    10新葡亰496net 20新葡亰496net 21        try新葡亰496net 22{
    11新葡亰496net 23新葡亰496net 24            if(_xmlDom == null && document.implementation && document.implementation.createDocument)新葡亰496net 25{
    12新葡亰496net 26                _xmlDom = document.implementation.createDocument("","",null);
    13新葡亰496net 27            }
    14新葡亰496net 28            isIE = false;
    15新葡亰496net 29新葡亰496net 30        }catch (ex)新葡亰496net 31{}
    16新葡亰496net 32    }

    function postRequest(url,parameters,callBack){
        if(xmlHttp !=null){
            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState == 4){
                    if(xmlHttp.status == 200){
                        xmlDom = getXmlDom(xmlHttp.responseText);
                        if(xmlDom != null){
                            eval(callBack(xmlDom));
                        }
                    }
                }
            }
            xmlHttp.open('Post',url,true);
            xmlHttp.setRequestHeader("Content-Length",parameters.length);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(parameters);
        }
    }
    getXmlHttp();

    "; //tempMessageContent[tempMessageContent.length]="

    // Appends the given value to the end of this instance.
    StringBuilder.prototype.append = function (value)
    {
        if (value)
        {
            this.strings.push(value);
        }
    }

       二、针对Firefox扩大Document的loadXML方法,使XMLDOM能像在IE中平等采纳loadXML加载XML

            细心大器晚成看铁锈红标记的代码,可不是这里不寻常么,用了大局的xmlHttp对象,那必然便是缓存的根本原因了,也怪一方始和谐太不认真了,写那样懒的代码。赶紧改一下.

    "; tempMessageContent[tempMessageContent.length]=""; tempMessageContent[tempMessageContent.length]=""; _window.open("update_or_not",feature); _window.write("update_or_not",tempMessageContent.join; THIS.ver=_current_version; _window.items["update_or_not"].all.onclick=function() { THIS.ver=_new_version; _window.close; THIS.update(); } _window.items["update_or_not"].all.onclick=function() { _window.close; } _window.items["update_or_not"].onunload=function() { } } } CLASS_AUTOUPDATE.prototype.update=function() { this.updating=!this.updating; vart=newDate(卡塔尔; varTHIS=this; if { //得到新安插文书档案 varnewDoc=newCLASS_XML(); newDoc.loadRemoteFile(this.updatePath this.softName "/" this.updateFileName); this.error=newDoc.error; if { THIS.updating=false; THIS.updateInfo="

    // Clears the string buffer
    StringBuilder.prototype.clear = function ()
    {
        this.strings.length = 1;
    }

     1新葡亰496net 33新葡亰496net 34Document.prototype.loadXML = function(sXml)新葡亰496net 35{
     2新葡亰496net 36    var oParser= new DOMParser();
     3新葡亰496net 37    var _xmlDom = oParser.parseFromString(sXml, "text/xml");
     4新葡亰496net 38    
     5新葡亰496net 39新葡亰496net 40while(this.firstChild)新葡亰496net 41{
     6新葡亰496net 42       this.removeChild(this.firstChild);
     7新葡亰496net 43    }
     8新葡亰496net 44
     9新葡亰496net 45新葡亰496net 46for(var i=0;i<_xmlDom.childNodes.length;i )新葡亰496net 47{
    10新葡亰496net 48       var oNewNode = this.importNode(_xmlDo.childNodes[i],true);
    11新葡亰496net 49        this.appendChild(oNewNode);
    12新葡亰496net 50    }
    13新葡亰496net 51}

    function getXmlHttp(){
        var _xmlHttp = null;
        if(window.XMLHttpRequest){
            _xmlHttp = new XMLHttpRequest();
            return _xmlHttp;
        }else if(window.ActiveXObject){
            var arrXmlHttpTypes = ['MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.3.0','Microsoft.XMLHTTP'];
            for(var i=0;i<arrXmlHttpTypes.length;i ){
                try{
                    _xmlHttp = new ActiveXObject(arrXmlHttpTypes[i]);
                    return _xmlHttp;
                }catch(ex){}
            }
        }
    }

    接连几日服务器战败

    // Converts this instance to a String.
    StringBuilder.prototype.toString = function ()
    {
        return this.strings.join("");
    }

    三、针对Firefox扩充Element的text属性,使XMLDOM能像在IE中平等接纳text获取节点的文本内容

    function getXmlDom(content){
        var _xmlDom = null;
        if (!window.DOMParser  && window.ActiveXObject){
            var arrXmlDomTypes = ['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];
            for(var i=0;i<arrXmlDomTypes.length;i ){
                try{
                    _xmlDom = new ActiveXObject(arrXmlDomTypes[i]);
                    _xmlDom.async = false;
                    _xmlDom.loadXML(content);
    //                _xmlDom.setProperty('SelectionLanguage', 'XPath');
                }catch(ex){}
            }
        }else{ 
            try{
                    var domParser = new window.DOMParser();
                    _xmlDom =  domParser.parseFromString(content, 'text/xml');
                    Element.prototype.selectSingleNode=function(sXPath){
                        var oEvaluator = new XPathEvaluator();
                        var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.FIRST_ORDERED_NODE_TYPE,null);
                        if(null != oResult){
                            return oResult.singleNodeValue;
                        }
                        return null;
                    }
                    
                    Element.prototype.selectNodes = function(sXPath){
                        var oEvaluator = new XPathEvaluator();
                        var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.ORDERED_NODE_摘自启点的main,在javascript中操作兼容IE。ITERATOR_TYPE,null);
                        var aNodes = new Array();
                        if(null != oResult){
                            var oElement = oResult.iterateNext();
                            while(oElement){
                                aNodes.push(oElement);
                                oElement = oResult.iterateNext();
                            }
                        }
                        return aNodes;
                    }
                    
                    Element.prototype.__defineGetter__("text",function(){ return this.textContent; });
            }
            catch (ex) 
            {
                
            }
        }
        return _xmlDom;
    }               

    "; } else { varupdateFileNodes=newDoc.selectNodes; varupdateInfoNode=newDoc.selectSingleNode; varnextVersion=newDoc.selectSingleNode; if { THIS.updateInfo=updateInfoNode.childNodes[0].text; } if { THIS.nextVersion=nextVersion.childNodes[0].text; } THIS.updateFileList=[]; for(vari=0;i0) { var_updateInfo=configXML.createElement; var_cdata=configXML.createCDATASection; _updateInfo.appendChild; configXML.root(卡塔尔(قطر‎.appendChild; //增多下版本预告var_nextVersion=configXML.selectSingleNode; if { var__next=configXML.createElement; var__cdata=configXML.createCDATASection; __next.appendChild; configXML.root; } else { if(_nextVersion.childNodes.length==0) { _nextVersion.appendChild(configXML.createCDATASection; } _nextVersion.childNodes[0].text=THIS.nextVersion; } configXML.setText("/Config","CurrentVersion",THIS.ver); configXML.save(); } configXML.dispose; } } } else { this.updateInfo="

    //string format prototype
    // sample: var test="my name is {0} {2} " ;
    //              alert(test.format('liang','zhonghua');
      if (!String._FORMAT_SEPARATOR){
            String._FORMAT_SEPARATOR = String.fromCharCode(0x1f);
            String._FORMAT_ARGS_PATTERN = new RegExp('^[^'   String._FORMAT_SEPARATOR   ']*'
                  new Array(100).join('(?:.([^'   String._FORMAT_SEPARATOR   ']*))?'));
        }
        if (!String.format)
        {
            String.format = function (s){
                return Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR).
                    replace(String._FORMAT_ARGS_PATTERN, s);
            }
        }
        if (!''.format)
        {
        String.prototype.format = function (){
            return (String._FORMAT_SEPARATOR 
                Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR)).
                replace(String._FORMAT_ARGS_PATTERN, this);
        }
    }
    //end string format

    1新葡亰496net 52新葡亰496net 53Element.prototype.__defineGetter__("text",function()新葡亰496net 54{ return this.textContent; });

    function postRequest(url,parameters,callBack){
        var xmlHttp = getXmlHttp();
        if(xmlHttp !=null){
            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState == 4){
                    if(xmlHttp.status == 200){
                        xmlDom = getXmlDom(xmlHttp.responseText);
                        if(xmlDom != null){
                            eval(func(xmlDom));
                        }
                    }
                }
            }
            xmlHttp.open('Post',url,true);
            xmlHttp.setRequestHeader("Content-Length",parameters.length);
            xmlHttp.setRequestHeader("Content-Type","appli也cation/x-www-form-urlencoded");
            xmlHttp.send(parameters);
        }
    }

    加载配置文件退步!

    function checkLoginByCookie()
    {
        var cookieId="AUTHTEST";
        if(window.location.href.toLowerCase().indexOf("qidian.com") > -1)
        {
            cookieId="cmfuToken";
        }

    四、针对Firefox扩充Element的selectNodes,selectSingleNode方法,使XMLDOM能像在IE中相似使用XPath获取节点。在那地自身只可以介绍一下网络传出的本子如下:

            最终在网络也招来了一下有关那一个题指标消除办法,有过多稿子介绍了另风度翩翩种方法,就是对异步调用的参数加上一个恣意数,笔者想,这么些艺术也太不忠实了啊,其它有少数值得借鉴的就是选取JSON实例化xmlHttp,将质量和办法用键值对方式完全包装,从可读性和扩充性上说,相对是个好主意。现在本人也时临时写写这么的事例。先放legend的版本如下,摘自(),带对象池的包裹:

    "; } this.updating=false; this.onafterupdate(); } CLASS_AUTOUPDATE.prototype.updateFile=function { vart=newDate(); varTHIS=this; for(vari=0;i

        if((GetCookie(cookieId)!=null && GetCookie(cookieId).length > 0 ))
        {
            return true;
        }
        else
        {
            if(GetCookie('cmfu_al') != null && GetCookie('cmfu_al').length > 0)
            {
                return true;
            }
        }
        return false;
    }

     1新葡亰496net 55if(document.implementation.hasFeature("XPath", "3.0") )
     2新葡亰496net 56新葡亰496net 57新葡亰496net 58{   
     3新葡亰496net 59   Document.prototype.selectNodes = function(cXPathString, xNode)
     4新葡亰496net 60新葡亰496net 61   新葡亰496net 62{
     5新葡亰496net 63新葡亰496net 64      if( !xNode ) 新葡亰496net 65{ xNode = this; } 
     6新葡亰496net 66      var oNSResolver = this.createNSResolver(this.documentElement)
     7新葡亰496net 67      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
     8新葡亰496net 68                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
     9新葡亰496net 69      var aResult = [];
    10新葡亰496net 70      for( var i = 0; i < aItems.snapshotLength; i )
    11新葡亰496net 71新葡亰496net 72      新葡亰496net 73{
    12新葡亰496net 74         aResult[i] =  aItems.snapshotItem(i);
    13新葡亰496net 75      }
    14新葡亰496net 76      return aResult;
    15新葡亰496net 77   }
    16新葡亰496net 78
    17新葡亰496net 79   Element.prototype.selectNodes = function(cXPathString)
    18新葡亰496net 80新葡亰496net 81   新葡亰496net 82{
    19新葡亰496net 83      if(this.ownerDocument.selectNodes)
    20新葡亰496net 84新葡亰496net 85      新葡亰496net 86{
    21新葡亰496net 87         return this.ownerDocument.selectNodes(cXPathString, this);
    22新葡亰496net 88      }
    23新葡亰496net 89新葡亰496net 90      else新葡亰496net 91{throw "For XML Elements Only";}
    24新葡亰496net 92   } 
    25新葡亰496net 93   
    26新葡亰496net 94   Document.prototype.selectSingleNode = function(cXPathString, xNode)
    27新葡亰496net 95新葡亰496net 96   新葡亰496net 97{
    28新葡亰496net 98新葡亰496net 99      if( !xNode ) 新葡亰496net 100{ xNode = this; } 
    29新葡亰496net 101      var xItems = this.selectNodes(cXPathString, xNode);
    30新葡亰496net 102      if( xItems.length > 0 )
    31新葡亰496net 103新葡亰496net 104      新葡亰496net 105{
    32新葡亰496net 106         return xItems[0];
    33新葡亰496net 107      }
    34新葡亰496net 108      else
    35新葡亰496net 109新葡亰496net 110      新葡亰496net 111{
    36新葡亰496net 112         return null;
    37新葡亰496net 113      }
    38新葡亰496net 114   }
    39新葡亰496net 115      
    40新葡亰496net 116   Element.prototype.selectSingleNode = function(cXPathString)
    41新葡亰496net 117新葡亰496net 118   新葡亰496net 119{    
    42新葡亰496net 120      if(this.ownerDocument.selectSingleNode)
    43新葡亰496net 121新葡亰496net 122      新葡亰496net 123{
    44新葡亰496net 124         return this.ownerDocument.selectSingleNode(cXPathString, this);
    45新葡亰496net 125      }
    46新葡亰496net 126新葡亰496net 127      else新葡亰496net 128{throw "For XML Elements Only";}
    47新葡亰496net 129   }
    48新葡亰496net 130}

    /**
     * XMLHttpRequest Object Pool
     *
     * @author    legend <legendsky@hotmail.com>
     * @link      
     * @Copyright www.ugia.cn
     */ 

    加载配置文件出错!

    function  getUrlParam(name)
    {   
        var reg = new RegExp("(^|&)"  name  "=([^&]*)(&|$)","i");   
        var r = window.location.search.substr(1).match(reg);   
        if (r!=null)  
        {
            return   unescape(r[2]);
        }
        else
        {  
            return   null;   
        }
    }  

    看过地点代码片段之后,我们也都会以为一定辛勤,用了多少个法子才扩展了Element的selectNodes,selectSingleNode方法,其实只须要稍作改正就行了,示范如下:

    var XMLHttp = {
        _objPool: [],

    "; } } } } CLASS_AUTOUPDATE.prototype.downloadFile=function { try { varxmlHTTP=newActiveXObject; xmlHTTP.open; xmlHTTP.send(卡塔尔(قطر‎; if(xmlHTTP.readyState==4&&xmlHTTP.status==200卡塔尔(قطر‎ { varadodbStream=newActiveXObject; //判别目录是或不是存在,不真实则开创 this.buildPath; varstrLocalUTiguanL=path.length>0?path "\" filename:filename; //1=adTypeBinary adodbStream.Type=1; adodbStream.Open(卡塔尔(قطر‎; adodbStream.write; adodbStream.SaveToFile; adodbStream.Close(卡塔尔(قطر‎; adodbStream=null; xmlHTTP=null; } else { this.error=true; returnfilename "下载失败"; } return""; } catch { this.error=true; returne.description; } } CLASS_AUTOUPDATE.prototype.refresh=function() { varconfigXML=newCLASS_XML("xml\autoupdate.xml"); if(configXML.error==false) { var_softName=configXML.selectSingleNode; var_updatePath=configXML.selectSingleNode; var_updateFileName=configXML.selectSingleNode("/Config/UpdateFileName"); this.updatePath=_updatePath!=null?_updatePath.text:""; this.softName=_softName!=null?_softName.text:"cc"; this.updateFileName=_updateFileName!=null?_updateFileName.text:"autoupdate.xml"; this.systemFiles={}; vartempSystemFileNodes=configXML.selectNodes("/Config/SystemFiles/SystemFile"); for(vari=0;i

    function $(objName)
    {

     1新葡亰496net 131新葡亰496net 132Element.prototype.selectSingleNode=function(sXPath)新葡亰496net 133{
     2新葡亰496net 134                    var oEvaluator = new XPathEvaluator();
     3新葡亰496net 135                    var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.FIRST_ORDERED_NODE_TYPE,null);
     4新葡亰496net 136新葡亰496net 137                    if(null != oResult)新葡亰496net 138{
     5新葡亰496net 139                        return oResult.singleNodeValue;
     6新葡亰496net 140                    }
     7新葡亰496net 141                    return null;
     8新葡亰496net 142                }
     9新葡亰496net 143                
    10新葡亰496net 144新葡亰496net 145                Element.prototype.selectNodes = function(sXPath)新葡亰496net 146{
    11新葡亰496net 147                    var oEvaluator = new XPathEvaluator();
    12新葡亰496net 148                    var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
    13新葡亰496net 149                    var aNodes = new Array();
    14新葡亰496net 150新葡亰496net 151                    if(null != oResult)新葡亰496net 152{
    15新葡亰496net 153                        var oElement = oResult.iterateNext();
    16新葡亰496net 154新葡亰496net 155                        while(oElement)新葡亰496net 156{
    17新葡亰496net 157                            aNodes.push(oElement);
    18新葡亰496net 158                            oElement = oResult.iterateNext();
    19新葡亰496net 159                        }
    20新葡亰496net 160                    }
    21新葡亰496net 161                    return aNodes;
    22新葡亰496net 162                }

        _getInstance: function ()
        {
            for (var i = 0; i < this._objPool.length; i  )
            {
                if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4)
                {
                    return this._objPool[i];
                }
            }

        if(document.getElementById)
        {
            return document.getElementById(objName );
        }
        else if(document.layers)
        {
            return eval("document.layers['"   objName  "']");
        }
        else
        {
            return eval('document.all.'   objName);
        }
    }

    总体上看上边几项,我们得以收拾出生龙活虎套较为完好的黄金时代对以备使用:

            // IE5中不帮衬push方法
            this._objPool[this._objPool.length] = this._createObj();

    function DateAdd(BaseDate, interval, DatePart)
    {
     var dateObj = new Date(BaseDate.replace("-",","));
     var millisecond=1;
     var second=millisecond*1000;
     var minute=second*60;
     var hour=minute*60;
     var day=hour*24;
     var year=day*365;

     1新葡亰496net 163var _xmlDom = null;
     2新葡亰496net 164新葡亰496net 165    if (!window.DOMParser  && window.ActiveXObject)新葡亰496net 166{
     3新葡亰496net 167        var arrXmlDomTypes = ['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];
     4新葡亰496net 168新葡亰496net 169        for(var i = 0;i<arrXmlDomTypes.length;i )新葡亰496net 170{
     5新葡亰496net 171新葡亰496net 172            try新葡亰496net 173{
     6新葡亰496net 174                _xmlDom = new ActiveXObject(arrXmlDomTypes[i]);
     7新葡亰496net 175新葡亰496net 176            }catch(ex)新葡亰496net 177{}//不支持MSXML.XMLDOM对象的IE
     8新葡亰496net 178        }
     9新葡亰496net 179新葡亰496net 180    }else新葡亰496net 181{// Mozilla browsers have a DOMParser
    10新葡亰496net 182新葡亰496net 183        try新葡亰496net 184{
    11新葡亰496net 185新葡亰496net 186            if(_xmlDom == null && document.implementation && document.implementation.createDocument)新葡亰496net 187{
    12新葡亰496net 188                _xmlDom = document.implementation.createDocument("","",null);
    13新葡亰496net 189
    14新葡亰496net 190新葡亰496net 191               Document.prototype.loadXML = function(sXml)新葡亰496net 192{
    15新葡亰496net 193    var oParser= new DOMParser();
    16新葡亰496net 194    var _xmlDom = oParser.parseFromString(sXml, "text/xml");
    17新葡亰496net 195    
    18新葡亰496net 196新葡亰496net 197    while(this.firstChild)新葡亰496net 198{
    19新葡亰496net 199    this.removeChild(this.firstChild);
    20新葡亰496net 200    }
    21新葡亰496net 201
    22新葡亰496net 202新葡亰496net 203    for(var i=0;i<_xmlDom.childNodes.length;i )新葡亰496net 204{
    23新葡亰496net 205    var oNewNode = this.importNode(_xmlDo.childNodes[i],true);
    24新葡亰496net 206        this.appendChild(oNewNode);
    25新葡亰496net 207    }
    26新葡亰496net 208}
    27新葡亰496net 209
    28新葡亰496net 210新葡亰496net 211 Element.prototype.__defineGetter__("text",function()新葡亰496net 212{ return this.textContent; });
    29新葡亰496net 213
    30新葡亰496net 214新葡亰496net 215Element.prototype.selectSingleNode=function(sXPath)新葡亰496net 216{
    31新葡亰496net 217                    var oEvaluator = new XPathEvaluator();
    32新葡亰496net 218                    var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.FIRST_ORDERED_NODE_TYPE,null);
    33新葡亰496net 219新葡亰496net 220                    if(null != oResult)新葡亰496net 221{
    34新葡亰496net 222                        return oResult.singleNodeValue;
    35新葡亰496net 223                    }
    36新葡亰496net 224                    return null;
    37新葡亰496net 225                }
    38新葡亰496net 226                
    39新葡亰496net 227新葡亰496net 228                Element.prototype.selectNodes = function(sXPath)新葡亰496net 229{
    40新葡亰496net 230                    var oEvaluator = new XPathEvaluator();
    41新葡亰496net 231                    var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
    42新葡亰496net 232                    var aNodes = new Array();
    43新葡亰496net 233新葡亰496net 234                    if(null != oResult)新葡亰496net 235{
    44新葡亰496net 236                        var oElement = oResult.iterateNext();
    45新葡亰496net 237新葡亰496net 238                        while(oElement)新葡亰496net 239{
    46新葡亰496net 240                            aNodes.push(oElement);
    47新葡亰496net 241                            oElement = oResult.iterateNext();
    48新葡亰496net 242                        }
    49新葡亰496net 243                    }
    50新葡亰496net 244                    return aNodes;
    51新葡亰496net 245                }
    52新葡亰496net 246            }
    53新葡亰496net 247            isIE = false;
    54新葡亰496net 248新葡亰496net 249        }catch (ex)新葡亰496net 250{}
    55新葡亰496net 251    }

            return this._objPool[this._objPool.length - 1];
        },

     var newDate;
     var dVal = new Date(dateObj)
     var dVal=dVal.valueOf();
     switch(DatePart)
     {
      case "ms": newDate=new Date(dVal millisecond*interval); break;
      case "s": newDate=new Date(dVal second*interval); break;
      case "mi": newDate=new Date(dVal minute*interval); break;
      case "h": newDate=new Date(dVal hour*interval); break;
      case "d": newDate=new Date(dVal day*interval); break;
      case "y": newDate=new Date(dVal year*interval); break;
      default: return escape("日期格式不对"卡塔尔(قطر‎;
     }
     newDate = new Date(newDate);
     return newDate.getFullYear()   "-"   (newDate.getMonth()   1)   "-"   newDate.getDate() ; 
    }

        将它包裹成function或然分开使用,客随主便,希望借此良策以解众博友之困,更迎接好的提出在此边集中。

        _createObj: function ()
        {
            if (window.XMLHttpRequest)
            {
                var objXMLHttp = new XMLHttpRequest();

    //增添当前日子的命局
    Date.prototype.AddDays=function (interval)
    {
         var dateObj = this;
     var millisecond=1;
     var second=millisecond*1000;
     var minute=second*60;
     var hour=minute*60;
     var day=hour*24;
     var year=day*365;

            }
            else
            {
                var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
                for(var n = 0; n < MSXML.length; n  )
                {
                    try
                    {
                        var objXMLHttp = new ActiveXObject(MSXML[n]);
                        break;
                    }
                    catch(e)
                    {
                    }
                }
             }          

     var newDate;
     var dVal = new Date(dateObj)
     var dVal=dVal.valueOf();

            // mozilla某个版本未有readyState属性
            if (objXMLHttp.readyState == null)
            {
                objXMLHttp.readyState = 0;

      newDate=new Date(dVal day*interval); 

                objXMLHttp.addEventListener("load", function ()
                    {
                        objXMLHttp.readyState = 4;

     newDate = new Date(newDate);
     return newDate
    }

                        if (typeof objXMLHttp.onreadystatechange == "function")
                        {
                            objXMLHttp.onreadystatechange();
                        }
                    },  false);
            }

    function SetCookie(name, value)
    {

            return objXMLHttp;
        },

    var argv = SetCookie.arguments;

        // 发送诉求(方法[post,get], 地址, 数据, 回调函数卡塔尔(قطر‎
        sendReq: function (method, url, data, callback)
        {
            var objXMLHttp = this._getInstance();

        var argc = SetCookie.arguments.length;

            with(objXMLHttp)
            {
                try
                {
                    // 加随机数幸免缓存
                    if (url.indexOf("?") > 0)
                    {
                        url  = "&randnum="   Math.random();
                    }
                    else
                    {
                        url  = "?randnum="   Math.random();
                    }

        var expires = (argc > 2) ? argv[2].toGMTString() : (new Date()).AddDays(30).toGMTString();;

                    open(method, url, true);

        var path = (argc > 3) ? argv[3] : "/";

                    // 设定乞请编码方式
                    setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
                    send(data);
                    onreadystatechange = function ()
                    {
                        if (objXMLHttp.readyState == 4 && (objXMLHttp.status == 200 || objXMLHttp.status == 304))
                        {
                            callback(objXMLHttp);
                        }
                    }
                }
                catch(e)
                {
                    alert(e);
                }
            }
        }
    };  

        var domain = (argc > 4) ? argv[4] : null;

        var secure = (argc > 5) ? argv[5] : false;

       
        var content = name   "="   escape(value)   ";";
        if(expires != null)
        {
            content  = " expires="   expires   ";";
        }
        if(path != null)
        {
            content  = " path="   path   ";";
        }
        if(domain != null)
        {
            content  = " domain="   domain   ";";
        }

        
        document.cookie = content;

    }

    function GetCookie(cookieName) 
    {
        var cookieString = document.cookie;

        var start = cookieString.indexOf(cookieName   '=');

        

        // 加上等号的缘由是幸免在少数 库克ie 的值里有
        // 与 cookieName 同样的字符串。

        if (start == -1) // 找不到
        return null;

        start  = cookieName.length   1;
        var end = cookieString.indexOf(';', start);
        if (end == -1) return unescape(cookieString.substring(start));
        return unescape(cookieString.substring(start, end));
    }

    /*文本框得到难点*/
    function TextBoxOnFocus(txtControl,strDefaultText)
    {
        if (txtControl.value==strDefaultText)
            txtControl.value="";
    }
    /*文本框失去大旨*/
    function TextBoxOnBlur(txtControl,strDefaultText)
    {
        if (txtControl.value.replace(/(^[s]*)|([s]*$)/g,"")=="")
            txtControl.value=strDefaultText;
    }

    /*职能:弹出群发音信窗口*/
    function MultiSendWin(subject,content)
    {
        var win =window.open(uploadURL "?subject="   subject   "&content="  content,"","menubar=no,width=480,height=550,resizeable=no","");
        return false;
    }

    /*作用:弹出留言窗口
    function SpaceSendMsg(toUserId)
    {
        var win =window.open(spaceSendMsgURL "?toUserId="   toUserId,"","menubar=no,width=500,height=400,resizeable=no","");
        return false;
    }
    */

    function ShowServerMessage(result)
    {
        eval(result.value);
    }

    //回车提交表单
    function KeydownSubmitForm(btnId)
    {
        var btn=document.getElementById(btnId);
        if (btn!=null&& event.keyCode== 13)
        {
             event.returnValue=false;
             event.keyCode=9;
             btn.click();  
        }  
    }  

    //ReadChapter -抵用券js
    function MDown(Object){
        Obj=Object.id
        document.all(Obj).setCapture()
        pX=event.x-document.all(Obj).style.pixelLeft;
        pY=event.y-document.all(Obj).style.pixelTop;
    }

    function MMove(){
        if(Obj!=''){
            document.all(Obj).style.left=event.x-pX;
            document.all(Obj).style.top=event.y-pY;
        }
    }

    function MUp(){
        if(Obj!=''){
            document.all(Obj).releaseCapture();
            Obj='';
        }
    }

    //关闭抵用券音讯
    function LayerClose(divDiscount){
        document.getElementById(divDiscount).style.visibility="hidden";
    }

    //显示抵用券新闻
    function LayerShow(divDiscount,discountPrize){
        var prizeUI = document.getElementById(divDiscount);
        prizeUI.style.left = screen.width-530;
        prizeUI.style.top = screen.Height - 480;
        prizeUI.style.visibility="visible";

        document.getElementById("lblPrize1").innerHTML=discountPrize;
        document.getElementById("lblPrize2").innerHTML=discountPrize;
        window.setInterval("LayerClose('"   divDiscount   "')",15000);
    }

    //帮助masterpage用
    function HideMenu(menuid)
    {
        var obj = document.getElementById(menuid);
        if(obj.style.display == "none")
        {
            obj.style.display = "";
        }
        else
        {
            obj.style.display = "none";
        }

        if(obj.style.display == "")
        {
            var tmpId = "M0";
            for(var i  = 1 ; i <= 9; i )
            {
                var myid = tmpId   i;
                if(myid != menuid)
                {
                    document.getElementById(myid).style.display = "none";
                }
            }
        }
    }

    /* div login */
    function ShowLoginDiv()
    {
        var builder = new StringBuilder();
        builder.append("<table border='0' cellpadding='0' cellspacing='0'>");
        builder.append("<tr class='TitleTR'>");
        builder.append("<td align='left'>");
        builder.append("登录");
        builder.append("</td>");
        builder.append("<td align='right'>");
        builder.append("<span title='关闭' onclick='HideLoginMask();'>×</span>");
        builder.append("</td>");
        builder.append("</tr>");
        builder.append("<tr>");
        builder.append("<td colspan='2'>");
        builder.append("<iframe src='/DivUserLogin.aspx' width='225px' height='125px' name='loginFrame' ");//src=''
        builder.append("id='loginFrame' frameborder='0' scrolling='no'></iframe>");
        builder.append("</td>");
        builder.append("</tr>");
        builder.append("</table>");    
        //window.top.scrollTo(0,0);
        document.getElementById("DivMask").style.height=document.body.scrollHeight;
        document.getElementById("DivMask").style.width=document.body.scrollWidth;
        document.getElementById("DivMask").style.display = 'block';                
        document.getElementById("DivLogin").style.display = "block";
        document.getElementById("DivLogin").innerHTML = builder.toString();
        ScrollDiv();  
        window.onscroll=ScrollDiv;
        window.onresize=ScrollDiv;
        window.onload=ScrollDiv; 

    function HideLoginMask()
    {
        document.getElementById("DivMask").style.display="none";
        document.getElementById("DivLogin").style.display="none";
    }        
    /*随显示器滚动*/
    function ScrollDiv()
    {
      if($("DivLogin"))
      {
        document.getElementById("DivLogin").style.top=(document.body.scrollTop
        (document.body.clientHeight-document.getElementById("DivLogin").offsetHeight)/2) "px";

        document.getElementById("DivLogin").style.left=(document.documentElement.scrollLeft
        (document.body.clientWidth-document.getElementById("DivLogin").offsetWidth)/2) "px";

       }

      if($("AddMark"))
      {
    //  if(!event )
    //        return;

        $("AddMark").style.top=document.body.clientHeight   document.body.scrollTop-200
        $("AddMark").style.left=document.body.clientWidth-56;
         $("AddMark").style.display=''; 

       // (document.body.clientHeight-$("AddMark").offsetHeight)/2) "px";
       if($("MonthVoteTip"))
       {
        //$("MonthVoteTip").style.top=document.body.scrollTop document.body.clientHeight-$("MonthVoteTip").offsetHeight "px";
       $("MonthVoteTip").style.top = getPosition($("AddMark")).y - $("AddMark").offsetHeight   "px";
       }
      }

    }
    function AutoScroll()
    {

        window.onscroll=ScrollDiv;
        window.onresize=ScrollDiv;
       window.onload=ScrollDiv; 
    }

    function getPosition(el)
    {
    for (var lx=0,ly=0;el!=null;lx =el.offsetLeft,ly =el.offsetTop,el=el.offsetParent);
    return {x:lx,y:ly}
    }

    /* 2007-11-28 XuJian */
    //截取字符串 包罗中文管理
    //(串,长度,增加...)
    function subString(str, len, hasDot)
    {
        var newLength = 0;
        var newStr = "";
        var chineseRegex = /[^x00-xff]/g;
        var singleChar = "";
        var strLength = str.replace(chineseRegex,"**").length;
        for(var i = 0;i < strLength;i )
        {
            singleChar = str.charAt(i).toString();
            if(singleChar.match(chineseRegex) != null)
            {
                newLength  = 2;
            }    
            else
            {
                newLength ;
            }
            if(newLength > len)
            {
                break;
            }
            newStr  = singleChar;
        }

        if(hasDot && strLength > len)
        {
            newStr  = "...";
        }
        return newStr;
    }

    /* 2007-10-26 14:20 Get String Lenth(include chinese character) */
    function GetStringLength(strObj)
    {
        return strObj.replace(/[^x00-xff]/g,"**").length;
    }

    function addMark(title,url) {
    try{
    if (window.sidebar) { 
    window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
    window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
    return true;
    }
    }catch(e)
    {
        alert("您的浏览器安全设置不许该项操作"卡塔尔(قطر‎
    }
    }

    ) { returnthis.replace(/(^s*)|(s*$)/g,""); } String.prototype.len=function() { returnthis.replace(/[^x00-xff]/g,'aa').length; } functionStringBuil...

    本文由新葡亰496net发布于服务器网络,转载请注明出处:摘自启点的main,在javascript中操作兼容IE

    关键词: