Js+activex Implementation page Select Local directory path dialog _javascript tips

Source: Internet
Author: User

Web page Select Local Directory Path dialog box, use ActiveX objects to traverse Local disk and directory, only the Web page to enable the relevant ActiveX Internet options, the local browser security requirements are not high, simple and easy-to-use.

Web page Select Local Directory Path dialog box sample

1. Open the main page "Select.html", click the "Select Path" button to enter the path selection page "Dir.html", select the Local directory path

2. After the path selection page "Dir.html" is initialized, load the local disk driver, and then load the directory on the selected disk path. If a subdirectory exists in the directory, double-click the directory list item to enter the next set of directories.

3. Click "OK", close the Select Path page "Dir.html", return the selected path value to the main page "select.html" text box


Copy Code code as follows:

/**//*
* Initialize, put all the drives of 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 = "[Drive not Ready]";
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 ();
}

/**//*
*tables_drives all folders in the selected drive list into 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 ("Cannot change the current content!") ")
}
}
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 Double-click an option in the option to display the folder below the folder in the Table_folder list.
*/
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);
}
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.