js弹出窗口 + 获取上传文件全路径。想点击“导入”可以能弹出这个文本框,回复给具体的代码,给采纳
<html><head><title>UntitledPage</title><scriptlanguage="javascript">functionreadFile(...
<html>
<head>
<title>Untitled Page</title>
<script language="javascript">
function readFile(fileBrowser) {
if (navigator.userAgent.indexOf("MSIE")!=-1) //浏览器为IE
readFileIE(fileBrowser);
else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Mozilla")!=-1) //浏览器为firefox
readFileFirefox(fileBrowser);
else
alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")");
}
//firefox获取文件全路径的方法
function readFileFirefox(fileBrowser) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');
return;
}
var fileName=fileBrowser.value;
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try {
// Back slashes for windows
file.initWithPath( fileName.replace(/\//g, "\\\\") );
}
catch(e) {
if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");
return;
}
if ( file.exists() == false ) {
alert("File '" + fileName + "' not found.");
return;
}
alert(file.path); // I test to get the local file's path.
}
//IE获取文件全路径方法
function readFileIE(fileBrowser) {
var path = fileBrowser.value;
alert("path is " + path);
}
</script>
</head>
<body>
<form name="form1">
Browse to select a file
<input type="file" name="fileBrowser" size="125" onchange="readFile(this)" style="display:none"/>
<input type="button" value="导入"/>
</form>
</body>
</html>
190分了,解决之后,秒采纳,没大神来解决吗? 展开
<head>
<title>Untitled Page</title>
<script language="javascript">
function readFile(fileBrowser) {
if (navigator.userAgent.indexOf("MSIE")!=-1) //浏览器为IE
readFileIE(fileBrowser);
else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Mozilla")!=-1) //浏览器为firefox
readFileFirefox(fileBrowser);
else
alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")");
}
//firefox获取文件全路径的方法
function readFileFirefox(fileBrowser) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');
return;
}
var fileName=fileBrowser.value;
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try {
// Back slashes for windows
file.initWithPath( fileName.replace(/\//g, "\\\\") );
}
catch(e) {
if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");
return;
}
if ( file.exists() == false ) {
alert("File '" + fileName + "' not found.");
return;
}
alert(file.path); // I test to get the local file's path.
}
//IE获取文件全路径方法
function readFileIE(fileBrowser) {
var path = fileBrowser.value;
alert("path is " + path);
}
</script>
</head>
<body>
<form name="form1">
Browse to select a file
<input type="file" name="fileBrowser" size="125" onchange="readFile(this)" style="display:none"/>
<input type="button" value="导入"/>
</form>
</body>
</html>
190分了,解决之后,秒采纳,没大神来解决吗? 展开
1个回答
展开全部
本文的地址是:
<script language=javascript>
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
alert(" 恭喜您!复制成功!\n\n 已经把该页网址复制到系统剪贴板 \n\n 您可以使脊蚂用(ctrl+v或鼠标右键)粘贴功能 \n\n 通过qq、msn或其搭野谈他软件发送给您的朋友或记录下来。");
}
document.write('<input name="page_url" value="'+window.location.href+'" size="38"> <input type="button" name="button" style=color:red value="复制本页知碰网址发给好友" onclick=JM_cc("page_url")>');
</script>
<script language=javascript>
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
alert(" 恭喜您!复制成功!\n\n 已经把该页网址复制到系统剪贴板 \n\n 您可以使脊蚂用(ctrl+v或鼠标右键)粘贴功能 \n\n 通过qq、msn或其搭野谈他软件发送给您的朋友或记录下来。");
}
document.write('<input name="page_url" value="'+window.location.href+'" size="38"> <input type="button" name="button" style=color:red value="复制本页知碰网址发给好友" onclick=JM_cc("page_url")>');
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询