感谢 http://www.yueshiyu.cn/post/70cbd_a9dfcb 作者 function previewImage(file,img,callback,backgroundDiv) { var path = "";//file.value var $img = $(img); var checkPic = function (path) { var accept = ["jpg", "bmp", "gif", “png”]; for (var i = 0; i < accept.length; i++) { if (path.indexOf(accept[i]) > -1) { return true; } } return false; } //大写浏览器信息 var browser_agent = navigator.userAgent.toUpperCase(); //如果window存在URL属性,则理应为现代浏览器支持HTML5 if (window.URL) { path = file.files[0].name; if (!checkPic(path)) { if(callback) callback(false); return}; var url = window.URL.createObjectURL(file.files[0]); $img.attr("src", url); if (callback) callback($img); //如果为IE浏览器 } else if (browser_agent.indexOf(“MSIE”) > -1) { path = file.value; if (!checkPic(path)) { if (callback) callback(false); return };
if (browser_agent.indexOf("MSIE 6.0") > -1) {
$img.attr("src", path);
if (callback) callback($img);
} else {
//如果有预留做为背景DIV
if (backgroundDiv) {
$(backgroundDiv)[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + path + "')";
}
if (callback) callback(false);
}
}
}
有无有类似的浏览器(bom)API资料哈,做这个功能时实在是苦于无资料…