html 通过js获得文件路径(适用于ie)
2014-05-07 16:03
260 查看
网页完整代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<link href="../CSS/rightStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function getPath() {
var fileinput = document.getElementById("file");
document.getElementById("filepath").value = getFilePath(fileinput);
/* alert(document.getElementById("filepath").value); */
}
/*
推荐IE浏览器,出于安全考虑,其他浏览器限制访问本地文件地址
2014.5.7
*/
function getFilePath(obj)
{
if(obj)
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
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>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center">
<tr height="30px">
<td width="20px"
style='padding-right: 4px; background-image: url("Images/right_title_1.gif");'>
<img src="Images/icon.gif" style="margin-left: 4px" width="12px"
height="12px" border="0" alt="" /></td>
<td width="100%"
style='background-image: url("Images/right_title_2.gif");'><span
id="RightMenu" style="color: #376EA6; font-size: 12px;">系统配置管理
>数据库恢复</span></td>
<td width="20px"
style='padding-left: 20px; background-image: url("Images/right_title_3.gif");'>
</td>
</tr>
</table>
<form name="form1" id="form1" method="post" action="dataRestore.action">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center"
style="text-align: center; font-size: 12px; margin-top: 10px"
class="table1">
<tr>
<th colspan="2" height="25px"
style="color: #FFFFFF; background-color: #376ea6; font-size: 13px">
数据库恢复</th>
</tr>
</table>
<fieldset style="margin-top: 10px;">
<legend>
<font style="font-size: 12px;" face="宋体" color="#0066CC">数据库恢复</font>
</legend>
<div style="text-align: center;">
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center" style="text-align: center; font-size: 12px;"
class="table1">
<tr>
<td
style="height: 30px; width: 45%; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库IP地址:</td>
<td align="left"><input type="text" name="ip" id="ip"
style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库登陆名:</td>
<td align="left"><input type="text" name="username"
id="username" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库登陆密码:</td>
<td align="left"><input type="text" name="password"
id="password" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库名称:</td>
<td align="left"><input type="text" name="dataname"
id="dataname" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>恢复文件:</td>
<td align="left"><input type="file" name="file"
id="file" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padd
a0e4
ing-right: 25px; font-size: 13px">
<font color="#DD3A90"></font></td>
<td align="left"><input type="hidden" name="filepath"
id="filepath" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td colspan="3" style="height: 30px;"><input type="submit"
name="submit" value="确定"
onClick="getPath()"
style="margin-left: 60px; color: #376EA6; background-color: #EAEAEA; border-color: #376EA6; border-width: 1px; border-style: solid; font-size: 12px; height: 22px; width: 60px;" />
<input type="reset" name="reset" value="重置"
style="margin-left: 40px; color: #376EA6; background-color: #EAEAEA; border-color: #376EA6; border-width: 1px; border-style: solid; font-size: 12px; height: 22px; width: 60px;" />
</td>
</tr>
</table>
</div>
</fieldset>
</div>
</form>
</body>
</html>
后台可以通过action获得
<input type="hidden" name="filepath"
id="filepath" style="font-size: 12px; width: 200px;" />
的值!
其他浏览器好像现在出于安全性考虑不让获得本地文件地址!
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<link href="../CSS/rightStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function getPath() {
var fileinput = document.getElementById("file");
document.getElementById("filepath").value = getFilePath(fileinput);
/* alert(document.getElementById("filepath").value); */
}
/*
推荐IE浏览器,出于安全考虑,其他浏览器限制访问本地文件地址
2014.5.7
*/
function getFilePath(obj)
{
if(obj)
{
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
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>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center">
<tr height="30px">
<td width="20px"
style='padding-right: 4px; background-image: url("Images/right_title_1.gif");'>
<img src="Images/icon.gif" style="margin-left: 4px" width="12px"
height="12px" border="0" alt="" /></td>
<td width="100%"
style='background-image: url("Images/right_title_2.gif");'><span
id="RightMenu" style="color: #376EA6; font-size: 12px;">系统配置管理
>数据库恢复</span></td>
<td width="20px"
style='padding-left: 20px; background-image: url("Images/right_title_3.gif");'>
</td>
</tr>
</table>
<form name="form1" id="form1" method="post" action="dataRestore.action">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center"
style="text-align: center; font-size: 12px; margin-top: 10px"
class="table1">
<tr>
<th colspan="2" height="25px"
style="color: #FFFFFF; background-color: #376ea6; font-size: 13px">
数据库恢复</th>
</tr>
</table>
<fieldset style="margin-top: 10px;">
<legend>
<font style="font-size: 12px;" face="宋体" color="#0066CC">数据库恢复</font>
</legend>
<div style="text-align: center;">
<table width="100%" border="0" cellpadding="0" cellspacing="0"
align="center" style="text-align: center; font-size: 12px;"
class="table1">
<tr>
<td
style="height: 30px; width: 45%; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库IP地址:</td>
<td align="left"><input type="text" name="ip" id="ip"
style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库登陆名:</td>
<td align="left"><input type="text" name="username"
id="username" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库登陆密码:</td>
<td align="left"><input type="text" name="password"
id="password" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>数据库名称:</td>
<td align="left"><input type="text" name="dataname"
id="dataname" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padding-right: 25px; font-size: 13px">
<font color="#DD3A90">* </font>恢复文件:</td>
<td align="left"><input type="file" name="file"
id="file" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td
style="height: 30px; text-align: right; padd
a0e4
ing-right: 25px; font-size: 13px">
<font color="#DD3A90"></font></td>
<td align="left"><input type="hidden" name="filepath"
id="filepath" style="font-size: 12px; width: 200px;" />
</td>
</tr>
<tr>
<td colspan="3" style="height: 30px;"><input type="submit"
name="submit" value="确定"
onClick="getPath()"
style="margin-left: 60px; color: #376EA6; background-color: #EAEAEA; border-color: #376EA6; border-width: 1px; border-style: solid; font-size: 12px; height: 22px; width: 60px;" />
<input type="reset" name="reset" value="重置"
style="margin-left: 40px; color: #376EA6; background-color: #EAEAEA; border-color: #376EA6; border-width: 1px; border-style: solid; font-size: 12px; height: 22px; width: 60px;" />
</td>
</tr>
</table>
</div>
</fieldset>
</div>
</form>
</body>
</html>
后台可以通过action获得
<input type="hidden" name="filepath"
id="filepath" style="font-size: 12px; width: 200px;" />
的值!
其他浏览器好像现在出于安全性考虑不让获得本地文件地址!
相关文章推荐
- 通过 js 获得文件上传路径
- 通过js获得选择文件的绝对路径
- 兼容IE和firefox,获得上传文件绝对路径
- j2ee中下载文件,js调用action,及获得tomcat的物理路径等知识点
- js 获得上传图片路径 FireFox IE
- 通过JS获取文件上传路径
- 通过JS获取文件上传路径
- j2ee中下载文件,js调用action,及获得tomcat的物理路径等知识点
- 关于iOS项目中引入Html5文件(html/js/css)的路径问题
- 本地的html怎么直接通过路径就读取本地文件。
- js通过事件获取页面元素对象-适用于IE、FireFox
- 本地的html怎么直接通过路径就读取本地文件。
- 使用 js 获得上传文件的真实路径 chrome 浏览器 除外
- js实现文件路径选择(限IE)
- IIS6.0中.css,.js等文件无法通过IE下载问题
- 通过js实现对html文件中控件属性的设置
- HTML/JSP引入JS文件路径问题解析
- DotNetNuke(DNN)皮肤制作-通过JS文件解决不同IE版本对CSS解释不一致的问题
- 通过js获得html标签的值
- 纯html页面中js如何获得项目路径