电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

在不同浏览器中获取File Input的路径


发布日期:2018/7/28
 

<head><title>File Input</title>

<meta httpequiv=contenttype content=text/html; charset=utf />

<style>

body{fontsize:px;}

box{border:px solid #eee;background:#ffe;padding:px px;margin:px;}

dt{fontweight:bold;}

dtimgtextarea{margin:px ;}

em{color:#f; fontstyle:normal;}

span{color:#;}

ft{color:#;fontsize:px;textalign:right}

</style>

</head>

<body>

<h>在不同浏览器中获取File Input的value</h>

<div class=box>

<input type=file name=foo id=foo size= />

<input type=button value=Show Value onclick=alert(documentgetElementById(foo)value) />

<input type=button value=Show Value in FF onclick=alert(getValueFF(foo)) />

<input type=button value=Show Value in IE onclick=alert(getValueIE(foo)) />

</div>

<div class=box>

<dl>

<dt>Firefox x IE IE</dt>

<dd>在本地及远端都可以取得完整地址(包括路径及文件名)</dd>

</dl>

<dl>

<dt>Firefox </dt>

<dd>在本地及远端都<em>不能</em>取得完整地址只能获得文件名</dd>

</dl>

<dl>

<dt>IE IE(IE模拟)</dt>

<dd>在本地可以取得完整地址(包括路径及文件名)在远端<em>不能</em>取得完整地址只能获得文件名</dd>

</dl>

<span>* 本地localhost</span>

</div>

<div class=box>

<h>如何在Firefox下取得完整路径</h>

<p>

第一步打开about:config页面查找debase_principal_support属性将其值设置为true

<p></p>

<p>

第二步在javascript中采用以下代码进行获取<br />

<textarea name=textarea >

function getValueFF(id){

var ip = documentgetElementById(id);

if (ipfiles) {

//ffx try to have access to full path

try {

netscapesecurityPrivilegeManagerenablePrivilege( UniversalFileRead )

}

catch (err) {

//need to set debase_principal_support to true

}

};

return ipvalue;

}

</textarea>

<p></p>

<p>

经过以上步骤在Firefox下获取file input的value时会弹出一个Internet Security的对话框点击Allow将可以获取完整value<br />

<span>资料<a target=_blank >_bugcgi?id=</a></span>

<p></p>

</div>

<div class=box>

<h>如何在IE下取得完整路径</h>

<p>方法一使用selectioncreateRange <br />

<textarea name=textarea >

function getValueIE(id){

var ip = documentgetElementById(id);

ipselect();

return documentselectioncreateRange()text;

}

</textarea>

<p></p>

<p>方法二引用<a _blank >;/a><p></p>

</div>

<script language=JavaScript>

function getValueFF(id){

var ip = documentgetElementById(id);

if (ipfiles) {

//ffx try to have access to full path

try {

netscapesecurityPrivilegeManagerenablePrivilege( UniversalFileRead )

}

catch (err) {

//need to set debase_principal_support to true

}

};

return ipvalue;

}

function getValueIE(id){

var ip = documentgetElementById(id);

ipselect();

return documentselectioncreateRange()text;

}

</script>

</body>

上一篇:在MFC中使用WPF技术

下一篇:MSDN:匿名方法