IE读取并显示本地图像文件的方法
<!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=gb2312" />
<title>get file input full path</title>
<script language='javascript'>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select(); alert(document.selection.createRange().text);
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>
</html>
~~~~以上的方法在 双击打开网页 或者 自己的电脑作为web服务器的情况 没问题,到时放到实际远程web服务器中 会因为浏览器的安全限制 IE还是不能获得用户所选文件在用户文件系统的绝对路径,较为好一点的方法 是滤镜加载图片 但是不够完美 如下:
----------------------------------------
<script type="text/javascript">
var himgCH; //头像在320视窗中的计算高度
$(function(){
var supportFileReader;
try{ if( (typeof FileReader) =='function') supportFileReader = true;}catch(e){ supportFileReader=false; }
var isie = navigator.userAgent.toLowerCase().indexOf('msie')>=0;
$('#himgfile').change(function(){
if(navigator.userAgent.toLowerCase().indexOf('msie')<0 || supportFileReader ){ //(!ie or ie10) chrome , firefox
var file = this.files[0]; //用户选择的文件
if(! /image\/\w+/.test(file.type) ){ //file.type 文件的mime值
alert("请选择图像文件");
}else{
var reader = new FileReader();
reader.readAsDataURL(file);//用户选择的文件readAsDataURL
reader.onload = function(){
// $('#pic4up').attr('src',this.result);
$('#p_up').attr('src', this.result);
$('#p_prev').attr('src', this.result);
var img = new Image();
img.src = this.result;
setTimeout(function(){ //不能马上获得img的计算高度 适当延时
// console.log(img.width);
$('#scale').val( img.width/320 );
himgCH = $('#p_up').height();
$('#p_up').height(himgCH);
$('#p_up').imgAreaSelect({aspectRatio:'1:1', onSelectChange: preview});
},100 );
}
}
}else{ //ie 6 7 8
//alert('using ie8- , file value:' + this.value);
// $('#pic4up')[0].src=this.value;
this.select();
// $('#pic4up')[0].src = document.selection.createRange().text;
var img = new Image(); //alert('choose file path:' + document.selection.createRange().text );
var fpath = document.selection.createRange().text; //获取文件域的路径
// $('#p_prev')[0].src = img.src = $('#p_up')[0].src = fpath; //文件本地路径 赋值给img.src 实现预览
//AlphaImageLoader实现预览 关键点: AlpahaImageLoader src=本地路径 加载的是客户端文件系统的本地路径 AlphaImageLoader加载的图片位于 容器背景和内容之间
img.src = fpath; //获取图片的原始尺寸
$('#p_prev,#p_up').each(function(i, ele, eles){
this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);";
this.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = fpath;
if(this.id == 'p_prev') this.src = 'images/blank320_320.gif';
});
setTimeout(function(){ //不能马上获得img的计算高度 适当延时
// alert(img.width);
$('#scale').val(img.width/320);
himgCH = $('#p_up').height();
$('#p_up').height(himgCH);
$('#p_up').imgAreaSelect({aspectRatio:'1:1', onSelectChange: preview});
},100 );
}
//$('.iMask').removeClass('hide');
$('.btn_disable').addClass('btn_enable');
});
IE读取并显示本地图像文件的方法的更多相关文章
- 读取input:file的路径并显示本地图片的方法
<!doctype html> <html> <head> <meta content="text/html; charset=UTF-8" ...
- 转:FileReader详解与实例---读取并显示图像文件
~~~针对需要读取本地图像,并立即显示在浏览器的情况,由于chrome firefox出于安全限制,input file并不返回文件的真实路径,经测试IE6/7/8都会返回真实路径,所以chrome, ...
- Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法
Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法 一.原因 Python 3 中虽有encoding 参数,但是对于有BOM(如Windows下用记事本指定为utf-8) ...
- Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果
版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/1873 ...
- js 读取外部的本地json文件
Javascript 读取外部的本地json文件 方案1 运行本地web服务器,提供文件服务 方案2 1.data = '[{"name" : "Ashwin" ...
- php中读取文件内容的几种方法。(file_get_contents:将文件内容读入一个字符串)
php中读取文件内容的几种方法.(file_get_contents:将文件内容读入一个字符串) 一.总结 php中读取文件内容的几种方法(file_get_contents:将文件内容读入一个字符串 ...
- java分享第十六天( java读取properties文件的几种方法&java配置文件持久化:static块的作用)
java读取properties文件的几种方法一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取Propert ...
- Winform实现Shp-栅格图形文件的读取与显示(外加shp转WKB格式存入oracle)附源码
前言:上学期GIS空间数据库课程设计时,老师让实现Shp-栅格图形文件的读取与显示,外加shp转WKB格式存入oracle,不使用第三方类库,花了一天时间在网上找了一些资料,实现了一个简单的栅格图形文 ...
- 在VC中显示和处理图片的方法
落鹤生 发布于 2011-10-21 09:12 点击:344次 来自:blog.csdn.net/mengaim_cn 几种用GDI画图的方法介绍. TAG: GDI 法1:这个方法其实用的是 ...
随机推荐
- 黑客瑞士军刀NC使用教程
###################################################################### 1. 写在前面的话 ################### ...
- docker基础入门之二
一.docker文件系统: linuxFS包括boot file system 和 root file system boot file system (bootfs),包含bootloader和ke ...
- URAL 1297 Palindrome 后缀数组
D - Palindrome Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- zoj 2067 White Rectangles
这题解决的算法处理,真的很难想清楚!!尤其是最后的正矩形如何处理.不过终于看懂了 #include<stdio.h> #include<stdlib.h> #include&l ...
- java中如何获取系统时间
需要引入的包有: import java.util.Date; 此为获取当前系统时间,合适为“1991-01-01” String now = ""; SimpleDateF ...
- Problem C: Andy's First Dictionary
Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...
- [置顶] WebService调用工具(AXIS2)
package com.metarnet.util; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Meth ...
- linux里source、sh、bash、./有什么区别
在linux里,source.sh.bash../都可以执行shell script文件,那它们有什么不同吗? ----------- 1.source source a.sh 在当前shell内去读 ...
- Python学习之路——初识Python
一.第一个程序Hello World: 1.打印输出Hello World: Python2打印方法: >>> print "hello world"hello ...
- PHP-语法(www.w3school.com.cn/php)
写在前面: 假设系统里已安装PHP软件 PHP是一种脚本语言,执行PHP脚本后向浏览器返回纯HTML语言(即后台将.php文件的执行结果以纯HTML的形式返回到前端) ---------------- ...