Home > Web Front-end > JS Tutorial > body text

JS ACTIVEX implements the web page selection local directory path dialog box_javascript skills

WBOY
Release: 2016-05-16 17:40:09
Original
1307 people have browsed it

The web page selects the local directory path dialog box, uses the ACTIVEX object to traverse the local disk and directory, and only needs to enable the relevant ACTIVEX INTERNET option on the web page. It does not require high security for the local browser and is simple and easy to use.

Web page select local directory path dialog box example

1. Open the main page "select.html", click the "Select Path" button to enter the path selection page "dir.html", and select the local directory path

2. After the path selection page "dir.html" is initialized, load the local disk drive, and then load the directories in it according to the selected disk path. If there are subdirectories in the directory, double-click the directory list item to enter the next episode directory.

3. Click "OK" to close the selection path page "dir.html" and return the selected path value to the "select.html" text box on the main page


Copy code The code is as follows:

/**//*
* Initialization, put all the drives in the system into the table_drives list
*/
window.onload = new function init()
{
var fso, s, n, e, x;
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.Drives);
s = "";
for (; !e.atEnd(); e.moveNext())
{
x = e.item();
s = s x.DriveLetter;
s = ":";
if (x.DriveType == 3)
n = x.ShareName;
else if (x.IsReady)
n = x.VolumeName;
else
n = "[驱动器未就绪]";
s = n ",";
}
var drives = s.split(",");
var tableDrives = document.getElementById("tables_drives");
for ( var i = 0; i < drives.length-1; i )
{
var option = document.createElement("OPTION");
drives[i].split(":");
option.value = "[" drives[i].split(":")[0] ":]" drives[i].split(":")[1];
option.text = "[" drives[i].split(":")[0] ":]" drives[i].split(":")[1];
tableDrives.add(option);
}
get_drives();
}

/**//*
*All folders on the drive selected in the tables_drives list are placed in the table_folder list
*/
function get_drives()
{
var tableDrives = document.getElementById("tables_drives");
var tableFolders = document.getElementById("table_folder");
for ( var i = 0; i < tableDrives.options.length; i )
{
if ( tableDrives.options[i].selected == true )
{
var fso, f, fc, s;
var drive = tableDrives.options[i].value.split(":")[0].substring(1,tableDrives.options[i].value.split(":")[0].length);
document.getElementById("backDir").value = drive ":\";
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.DriveExists(drive))
{
d = fso.GetDrive(drive);
if ( d.IsReady )
{
f = fso.GetFolder(d.RootFolder);
fc = new Enumerator(f.SubFolders);
s = "";
for (;!fc.atEnd(); fc.moveNext())
{
s = fc.item();
s = ",";
}

var len = tableFolders.options.length;
while(len >= 0)
{
tableFolders.options.remove(len);
len--;
}
var option = document.createElement("OPTION");
option.value = drive ":\";
option.text = drive ":\";
tableFolders.add(option);
var folders = s.split(",");
for ( j = 0; j < folders.length -1; j )
{
option = document.createElement("OPTION");
option.value = folders[j];
option.text = folders[j];
tableFolders.add(option);
}
}
else
{
alert("无法改变当前内容!")
}
}
else
return false;
}
}
}
function get_fileName()
{

var tableFolders = document.getElementById("table_folder");
for ( var i = 0; i < tableFolders.options.length; i )
{
if ( tableFolders.options[i].selected == true )
{
var folderpath = tableFolders.options[i].value.substring(0,tableFolders.options[i].value.length);
if ( folderpath.charAt(folderpath.length-1) == "\" )
{
document.getElementById("backDir").value = folderpath;
}
else
{
document.getElementById("backDir").value = folderpath "\";
}
}
}
}
/**//*
*table_folder双击选项中的一个选项,就将该文件夹下面的文件夹显示在table_folder列表中。
*/
function get_file()
{
var tableFolders = document.getElementById("table_folder");
var tableDrives = document.getElementById("tables_drives");
for ( var i = 0; i < tableFolders.options.length; i )
{
if ( tableFolders.options[i].selected == true )
{
var fso, f, fc, s;
var folderpath = tableFolders.options[i].value.substring(0,tableFolders.options[i].value.length);
if ( folderpath.charAt(folderpath.length-1) == "\" )
{
document.getElementById("backDir").value = folderpath;
}
else
{
document.getElementById("backDir").value = folderpath "\";
}


fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderpath);
fc = new Enumerator(f.SubFolders);
s = "";
for (;!fc.atEnd(); fc.moveNext())
{
s = fc.item();
s = ",";
}
var len = tableFolders.options.length;
while(len >= 0)
{
tableFolders.options.remove(len);
len--;
}
var opt = "";
var opt1 = "";
for ( j = 0; j < folderpath.split("\").length; j )
{
var option = document.createElement("OPTION");
opt = opt folderpath.split("\")[j] "\";
if ( j > 0)
{
opt1 = opt;
option.value = opt1.substring(0,opt1.length-1);
option.text = opt1.substring(0,opt1.length-1);
tableFolders.add(option);
}
else
{
option.value = opt;
option.text = opt;
tableFolders.add(option);
}

}
if ( tableFolders.options[0].value == tableFolders.options[1].value )
{
tableFolders.options.remove(1);
}
if ( s != "" )
{
var folders = s.split(",");
for ( j = 0; j < folders.length -1; j )
{
option = document.createElement("OPTION");
option.value = folders[j];
option.text = folders[j];
tableFolders.add(option);
}
}
}
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template