As shown in the figure:
You can return a directory path.
The operation is as follows:
function Browsefolder () {
try{
var message = "Please select folder";//selection box hint info
var Shell = new ActiveXObject (" Shell.Application ");
var folder = Shell.browseforfolder (0,message,0x0040,0x11);//The Starting directory is: My Computer
//var Folder = Shell.browseforfolder (0, message,0); The starting directory is: Desktop
if (folder!= null) {
folder = Folder.items ();//Return Folderitems object
folder = Folder.item ();//Back to Fol Deritem Object
folder = Folder.path//return path
if (Folder.charat (folder.length-1)!= "\") {
folder = folder + "\" ;
}
return Folder;
}
return null;
} catch (e) {
alert ("Please enable the Acitvex control related options in the IE settings. ");
return null;
}
}
var Folder = Browsefolder ();
Here This folder is the path that is returned after the selection directory is determined.
Suppose I selected the Works directory on E disk, the return value is E:\works\
Note: Sometimes you may be prompted with no permissions and so on, because it is a client-side JS operation, so you need to enable some of the ActiveX options in the security customization of the Internet option.