zoukankan      html  css  js  c++  java
  • 实时编辑dom的代码,包含新的判断浏览器核心及版本的方法,留存参考

    //"mozilla/5.0 (windows nt 6.3; wow64; trident/7.0; .net4.0e; .net4.0c; infopath.3; .net clr 3.5.30729; .net clr 2.0.50727; .net clr 3.0.30729; rv:11.0) like gecko"
    //"mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, like gecko) chrome/46.0.2490.80 safari/537.36"
    // mozilla/5.0 (windows nt 6.3; wow64; rv:43.0) gecko/20100101 firefox/43.0
    //"mozilla/5.0 (windows nt 6.3; wow64; trident/7.0; .net4.0e; .net4.0c; infopath.3; .net clr 3.5.30729; .net clr 2.0.50727; .net clr 3.0.30729; qqbrowser/8.0.3328.400; rv:11.0) like gecko" 
    
    function browserInfo() {
        var agent = navigator.userAgent.toLowerCase(),
            regStr_ie = /msie [d.]+;/gi,
            regStr_ierv = /rv:[d.]+/gi,
            regStr_ff = /firefox/[d.]+/gi,
            regStr_chrome = /chrome/[d.]+/gi,
            regStr_saf = /safari/[d.]+/gi,
            browser = {};
        if(agent.indexOf("msie") > 0) {
            browser.info = agent.match(regStr_ie) ;
        }
        if(agent.indexOf("rv:") > 0) {
            browser.info = agent.match(regStr_ierv);
        }
        if(agent.indexOf("firefox") > 0) {
            browser.info = agent.match(regStr_ff);
        }
        if(agent.indexOf("chrome") > 0) {
            browser.info = agent.match(regStr_chrome);
        }
        if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
            browser.info = agent.match(regStr_saf);
        }
        browser.version = (browser.info + "").replace(/[^0-9.]/ig, "");
        return browser;
    }
    var insertHtml = function (html) {
        var selection = window.getSelection ? window.getSelection() : document.selection,
            range = selection.createRange ? selection.createRange() : selection.getRangeAt(0);
        var browser = browserInfo();
        if (browser.info.indexOf('msie') > 0 && browser.version < 9) {
            range.pasteHTML(html);
        } else {
            //var node = document.createElement('span');
            //node.innerHTML = html;
            //range.insertNode(node);
            range.insertNode($(html)[0]);
            selection.addRange(range);
        }
    }
    var insertImg = function (img) {
        this.insertHtml("<img src='" + img + "'/>");
    }

  • 相关阅读:
    热烈祝贺自己的博客进入前1000名
    烈日之后逛成都
    懂得爱情
    腾飞天涯
    哈佛教授教你成为No.1的秘诀
    烈日炎炎
    有缘无份——因为伤感所以美丽
    时间管理
    亲爱的陌生人(转)
    走好激励第一步
  • 原文地址:https://www.cnblogs.com/foren/p/6009092.html
Copyright © 2011-2022 走看看