Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Code for Browsing Folders Does Not Work

Status
Not open for further replies.

paradisewolf

Programmer
Mar 15, 2007
17
GB
Why this javascript code does not work ?

~~~~~~~~~~~~~~~~~~~~~~~~~~

<html>
<head>

<title>Untitled Page</title>

<script language=javascript>

<!--

function GetDownloadPath()
{
var frm = document.forms[0];
var Shell = new ActiveXObject("Shell.Application");
var Folder = new Object;

Folder = Shell.BrowseForFolder(0, "Choose a download folder", 0);

var FolderItem = new Object;
FolderItem = Folder.Items().Item();

document.all.item("lblFilepath").InnerText = FolderItem.Path;
frm.lblFilepath.Text = FolderItem.Path;
}
-->
</SCRIPT>

</head>

<body>
<FORM name="Form1">

<input type="Button" name="Button1"
value="Get Download Path" onClick="GetDownloadPath()" />

</FORM>

</body>
</html>
 
In non-IE browsers? Because ActiveX is not supported.

In IE? Most likely because the security permissions applied to that site are insufficient to allow the scripting of unsafe ActiveX controls.

Try putting the site that this code is on in your Trusted Sites zone.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Enable Apps
 
Hi dwarfthrower

{{In IE? Most likely because the security permissions applied to that site are insufficient to allow the scripting of unsafe ActiveX controls.}}

I have IE 6 in my computer. I enabled all ActiveX settings. But it is not working. It shows “Error on Page” in the left bottom corner.

{{Try putting the site that this code is on in your Trusted Sites zone.}}

It does not belong to any web site. It is just a html file in my computer.

What else could be ?

Does this code work in your browser ?
 
Does it work in my browser... using IE6, yes if I run it from my web site, which I have included in my Trusted Sites zone. No if I run it from my file system which is part of the My Computer zone and has much more severe restrictions.

At least it runs up until the point where you are trying to access an item that doesn't exist on the page:
Code:
document.all.item("lblFilepath").InnerText = FolderItem.Path;
But that would be solved by putting a "lblFilepath" object on the document.

So what you need to do is run it from a web server, and put that server's address into your Trusted Sites zone (recommended), or lower the permissions on your My Computer zone (not recommended)

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top