<script type= "Text/javascript" >
//fx Get File path method
function Readfilefirefox (filebrowser) {
try {
Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
}
catch (e) {
alert (' Cannot access local files due to browser security settings. To overcome this, follow these steps: (1) in the Address bar, enter "About:config";(2) Right-click and select new->boolean; (3) Enter the name "Signed.applets.codebase_principal_support" (without quotes) as a new preference; (4) Click OK and try reloading the file ');
return;
}
var filename=filebrowser.value; This step will get the full client path. The following is too complex to judge, and the following get IE is also very complex.
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 is loaded:relative paths are not allowed. Please provide a absolute path to this file. ");
return;
}
if (file.exists () = False) {
alert ("File" + fileName + "' not found.");
return;
}
return file.path;
}
//Access paths based on different browsers
function Getvl () {
//Judge Browser
var Sys = {};
var ua = Navigator.userAgent.toLowerCase ();
var s;
(s = Ua.match (/msie) ([D.] +)/)) ? sys.ie = s[1]:
(s = Ua.match (/firefox/) ([D.] +)/)) ? Sys.firefox = s[1]:
(s = Ua.match (/chrome/) ([D.] +)/)) ? Sys.chrome = s[1]:
(s = Ua.match (/opera) ( [D.] +)/)) ? Sys.opera = s[1]:
(s = Ua.match (/version/) ([D.] +). *safari/)? Sys.safari = S[1]: 0;
var file_url= "";
if (sys.ie<= "6.0") {
//ie5.5,ie6.0
File_url = document.getElementById ("file"). Value;
}else if (sys.ie>= "7.0") {
//IE7,IE8
var file = document.getElementById ("file");
File.select ();
File_url = Document.selection.createRange (). text;
}else if (sys.firefox) {
//fx
//file_url = document.getElementById ("file"). Files[0].getasdataurl ()//The path obtained is an encrypted string recognized by FF
File_url = Readfilefirefox (document.getElementById ("file"));
}
//alert (File_url);
document.getElementById ("text"). Innerhtml= "Get the complete path to the file domain is:" +file_url;
}
</script>
<h1>js Gets the full path to the file domain, compatible with different browsers </h1>
<div id= "text" style= "color: #f00;" ></div>
<input type= "file" id= "file"/>
<input name= "type=" button "value=" gets "onclick=" GETVL (); >