- 浏览: 30448 次
- 性别:
- 来自: 湖北
最新评论
-
白色蜻蜓:
准备向objc进展准备中。。。
Objective-C -
day6:
请教下:不要用StringBuffer代替字符串相加 这是为 ...
高性能JAVA开发之内存管理 -
……蚂蚁……:
不错 湖北的 顶
用collection.sort()方法对list集合排序
jsp预览图片——兼容firefox IE7 IE8
- 博客分类:
- java综合
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Firefox3,IE6,IE7,IE8上传图片预览</title>
<style type="text/css">
#preview_wrapper{
display:inline-block;
width:300px;
height:300px;
background-color:#CCC;
}
#preview_fake{ /* 该对象用户在IE下显示预览图片 */
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
(sizingMethod=scale);
}
#preview_size_fake{ /* 该对象只用来在IE下获得图片的原始尺寸,无其它用途 */
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
(sizingMethod=image);
visibility:hidden;
}
#preview{ /* 该对象用户在FF下显示预览图片 */
width:300px;
height:300px;
}
</style>
<script type="text/javascript">
function onUploadImgChange(sender){
if( !sender.value.match( /.jpg|.gif|.png|.bmp/i ) ){
alert('图片格式无效!');
return false;
}
var objPreview = document.getElementById( 'preview' );
var objPreviewFake = document.getElementById( 'preview_fake' );
var objPreviewSizeFake = document.getElementById( 'preview_size_fake'
);
if( sender.files && sender.files[0] ){
objPreview.style.display = 'block';
objPreview.style.width = 'auto';
objPreview.style.height = 'auto';
// Firefox 因安全性问题已无法直接通过 input[file].value 获取完整的
文件路径
objPreview.src = sender.files[0].getAsDataURL();
}else if( objPreviewFake.filters ){
// IE7,IE8 在设置本地图片地址为 img.src 时出现莫名其妙的后果
//(相同环境有时能显示,有时不显示),因此只能用滤镜来解决
// IE7, IE8因安全性问题已无法直接通过 input[file].value 获取完整的
文件路径
sender.select();
var imgSrc = document.selection.createRange().text;
objPreviewFake.filters.item(
'DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;
objPreviewSizeFake.filters.item(
'DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;
autoSizePreview( objPreviewFake,
objPreviewSizeFake.offsetWidth,
objPreviewSizeFake.offsetHeight );
objPreview.style.display = 'none';
}
}
function onPreviewLoad(sender){
autoSizePreview( sender, sender.offsetWidth, sender.offsetHeight );
}
function autoSizePreview( objPre, originalWidth, originalHeight ){
var zoomParam = clacImgZoomParam( 300, 300, originalWidth,
originalHeight );
objPre.style.width = zoomParam.width + 'px';
objPre.style.height = zoomParam.height + 'px';
objPre.style.marginTop = zoomParam.top + 'px';
objPre.style.marginLeft = zoomParam.left + 'px';
}
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
var param = { width:width, height:height, top:0, left:0 };
if( width>maxWidth || height>maxHeight ){
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if( rateWidth > rateHeight ){
param.width = maxWidth;
param.height = height / rateWidth;
}else{
param.width = width / rateHeight;
param.height = maxHeight;
}
}
param.left = (maxWidth - param.width) / 2;
param.top = (maxHeight - param.height) / 2;
return param;
}
</script>
</head>
<body>
<div id="preview_wrapper">
<div id="preview_fake">
<img id="preview" onload="onPreviewLoad(this)"/>
</div>
</div>
<br/>
<input id="upload_img" type="file" onchange="onUploadImgChange
(this)"/>
<br/>
<img id="preview_size_fake"/>
</body>
</html>
发表评论
-
android
2011-08-29 20:47 0http://www.mars-droid.com/ -
高性能JAVA开发之内存管理
2011-07-26 17:17 1027一、JVM中的对象生命周期 对象的生命周期一般分为7个阶段: ... -
DIV+CSS
2011-07-19 22:41 0DIV+CSS -
java面试参考
2011-03-01 22:58 729java面试参考 -
linux命令大全
2011-03-01 22:53 632linux命令大全 -
我的个人资料
2011-02-28 07:46 699我的个人资料 -
在Ant中使用javac命令,出现资源不足解决方案
2011-02-22 16:26 4368在Ant中使用javac命令,抛出的java.lang.Out ... -
快速排序
2011-02-22 11:50 0快排是分治法的一个应用,快排主要是通过一个设定枢轴,然后以这个 ... -
XML的4中解析方式
2011-02-21 15:19 827XML现在已经成为一种通 ... -
BeanShell执行标准Java语句和表达式
2011-02-18 16:01 1848在项目中可能会遇到各种不同的公式计算,如:result= 变量 ... -
Escape,encodeURI,encodeURIComponent
2010-11-08 10:45 926Escape,encodeURI,encodeURICom ... -
Objective-C
2010-10-24 16:43 1047Objective-C,通常写作ObjC和较少用的Ob ... -
js中禁止粘贴text
2010-10-21 16:34 953<body> <script type=&q ... -
获取中文汉字所占的字符长度
2010-10-21 16:29 801<script> alert (fucChe ... -
ibatis动态查询条件
2010-10-16 22:32 1083IBatis 动态查询条件 下面这个配置基本上包含了最复杂的 ... -
用collection.sort()方法对list集合排序
2010-10-03 17:11 1875第一种是list中的对象实现Comparable接口,如下: ... -
基于jQuery的AJAX和JSON实现纯html数据模板
2010-07-28 21:52 2207通过jQuery内置的AJAX功能,直接访问后台获得JSON格 ... -
java.sql.Date、java.util.Date与数据库中的Date字段的转换方法
2010-07-20 20:51 1338JAVA 处理时间 - java.sql.Date、java. ...
相关推荐
Firefox, IE5, IE5.5, IE6, IE7, IE8多种浏览器兼容的问题,解决以上浏览器存在的兼容问题
jsp网络编程——多媒体文件(7),对初学者很有帮助的
Jsp图片预览程序(含Java源码) 目前,很多网站都在为提升用户体验而努力,想尽多种办法让用户在网站上...程序中的JavaScript部分兼容ie6/7/8, firefox 3.5.5以及opera 10、safari 4.0.4、 chrome 3.0 等多种浏览器。
博主在网上找到了剥离出来的百度开发的ueditor中有多图片上传功能的例子(仅针对JSP),加上之前的适应IE8+的预览JS,二者结合,则既可以上传图片,又可以预览图片。 适应IE8+的预览JS: 下载网址为:...
最近为eWebEditor编辑器兼容烦,网上搜索到"eWebEditor7.0破解版",测试了一下,发现还是有缺陷,抽时间做了修正,顺便把ASP、JSP版和PHP版也完善了。 JSP版在Linux+Tomcat环境下测试过没问题! 希望对有同样烦恼...
JSP核心技术——JSP引擎内幕(2010).pdf 内除了引擎外,还有jsp标签、线程安全
jsp网络编程——源文件(06——09)帮助
jsp网络编程——源文件(10——11)帮助
jsp网络编程——源文件(12——13),帮助
jsp网络编程——源文件(01——05),帮助
jsp网络编程——多媒体文件(8),对学习用帮助
jsp 文件上传浏览,支持ie6,ie7,ie8.docx
jsp毕业设计——jsp报名系统.zip
JSP网络编程——多媒体(1——3),对出学者很有帮助的。
JSP技巧收集——超多超赞的JSP实用小技巧哦!
jsp毕业设计——jsp网上选课系统.zip
JSP扩展——自定义标签JSP扩展——自定义标签JSP扩展——自定义标签JSP扩展——自定义标签JSP扩展——自定义标签
jsp毕业设计——jsp企业人事管理系统.zip
jsp毕业设计——jsp商品进销存系统.zip
jsp毕业设计——jsp-企业人事管理系统.zip