IE8.0 显示本地图片 img.src=本地图片路径无效的解决方案

IE8.0 显示本地图片 img.src=本地图片路径 是无效,只能通过div来完成 。

IE7,IE8是放在

里的。

JS代码:

 function Preview(obj) {

            obj.select();
           
            //得到真实的图片路径
            var realpath = document.selection.createRange().text;
 
            var browser = getBrowserInfo();          
            var verinfo = (browser + "").replace(/[^0-9.]/ig, "");
                     
            if (verinfo == "8.0") {

                document.getElementById("imgPreview").innerHTML = "";
                document.getElementById("imgPreview").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src=\"" + realpath + "\")"; //使用滤镜效果,sizingMethod='scale'

            }
            else {
                document.getElementById("Image1").src = realpath;
            }
        }


        function getBrowserInfo() {
            var agent = navigator.userAgent.toLowerCase();

            var regStr_ie = /msie [\d.]+;/gi;
            var regStr_ff = /firefox\/[\d.]+/gi
            var regStr_chrome = /chrome\/[\d.]+/gi;
            var regStr_saf = /safari\/[\d.]+/gi;
            //IE
            if (agent.indexOf("msie") > 0) {
                return agent.match(regStr_ie);
            }

            //firefox
            if (agent.indexOf("firefox") > 0) {
                return agent.match(regStr_ff);
            }

            //Chrome
            if (agent.indexOf("chrome") > 0) {
                return agent.match(regStr_chrome);
            }

            //Safari
            if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
                return agent.match(regStr_saf);
            }

        }

 

HTML代码:

 


                           
      

 

 

你可能感兴趣的:(BS开发)