js上传前预览,兼容IE、谷歌等浏览器
来源:互联网 发布:智慧的云计算pdf 编辑:程序博客网 时间:2024/05/23 19:13
function getFileUrl(sourceId) { var url; if (navigator.userAgent.indexOf('Trident')>0&&(navigator.userAgent.indexOf('rv:11')>-1)) { // IE11 url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); }else if(navigator.userAgent.indexOf('MSIE')>-1){ if(navigator.appVersion.indexOf('10.0')>0){ url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); }else{ var docObj=document.getElementById(sourceId); docObj.select(); docObj.blur(); var imgSrc = document.selection.createRange().text; var localImagId = document.getElementById("localImag"); localImagId.style.width = "100px"; localImagId.style.height = "100px"; try { localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="+imgSrc+")"; localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc; } catch (e) { alert("您上传的图片格式不正确,请重新选择!"); return false; } document.selection.empty(); } } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } else if (window.webkitURL != undefined) { url = window.webkitURL.createObjectURL(document.getElementById(sourceId).files.item(0)) } return url;}
$(function() {$("#inputlicenseImage").change(function(){ var url = getFileUrl("inputlicenseImage"); $("#imglicenseImage").attr("src", url); });});
<input type="file" id="inputlicenseImage" class="default" name="licenseImage" /><div class="col-md-4" id="localImag"> <img id="imglicenseImage" src="" width="100px" height="100px" class="form-control-static" data-display="licenseImage" /></div>今天研究了好久终于兼容IE11等版本!也把IE10-IE8都兼容了 IE8一下没测
0 0
- js上传前预览,兼容IE、谷歌等浏览器
- IE火狐谷歌等主流浏览器--图片上传预览
- js图片上传预览兼容IE
- 浏览器本地预览图片并Ajax上传到服务器(谷歌火狐 ,IE不兼容)
- js 图片的上传前预览上传的图片(兼容所有浏览器)
- 本地图片上传预览(兼容ie firefox ,chrome等主流浏览器
- 图片上传前预览,支持IE各版本、火狐、谷歌浏览器
- js实现上传图片实时预览,兼容chrome IE firefox多浏览器
- js上传图片预览功能代码,兼容IE,FireFox,Chrome浏览器
- 图片上传前预览(兼容FF和IE)
- 兼容IE和FF的上传前预览
- 图片上传前的本地预览,兼容IE的方法
- javascript上传图片前预览图片兼容大多数浏览器
- JavaScript 图片的上传前预览(兼容所有浏览器)
- javascript js 返回顶部 源代码 兼容ie火狐谷歌等浏览器
- ireport超链接支持js事件简单实现 兼容火狐谷歌IE等浏览器
- IE兼容上传图片预览
- 兼容浏览器图片上传本地预览功能js脚本
- 教你如何做一款让用户上瘾的产品
- AutoFac20150128
- Python权威指南之如何使用静态类或抽象函数
- Java异常的分类
- C++ Builder 全部API函数列表
- js上传前预览,兼容IE、谷歌等浏览器
- SDK Manager 更新不了的解决方案(亲测完美)
- linux 简单shell
- java学习记录(四)继承与访问权限的学习与总结
- 小康家庭存款70万,精明理财移民新西兰
- 从iOS应用中,启动一个Unity App
- IOS使用CGContextRef动态画折线图
- 13.返回通知&异常通知&环绕通知
- online_judge_1106