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>
Could it be your browser? If you are using Firefox most javascript codes needs to be rewritten properly. I'm using IE and after pressing the button a path dialog is opened to let me choose a directory
Hi Tauren I am also using IE 6, yet it shows "Error on Page". Is there some setting that I need to change in my IE browser ?
Then maybe is a missing component on your system, but you can get rid of such error adding an error blocker this way: <html> <head> <title>Untitled Page</title> <script type="text/javascript" language="javascript"><!-- function error() { return true; } window.onerror = error; //--></script> <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> Code (markup):
Hi “Your Content†Someone told me that this code only works when it runs from within a web site whose URL address starts with “https†instead of “httpâ€. And additionally, it has to be listed within “Trusted Sites†in the IE Security settings. Is that true ?
Don't think so, I tested it on my PC and upload to my http site and it's working fine, see http://www.yourcontent.net/test.htm or https://www.yourcontent.net/test.htm In addition, I havee IE security options set as default to all values and cookies at the lower in order to accept all of them because both features are annoying for testing and surfing purposes. As I told you adding this at the top of your script will stop the error whether your Trusted Sites setting or access URL <script type="text/javascript" language="javascript"><!-- function error() { return true; } window.onerror = error; //--></script> Code (markup): Hey, I have found one issue after posting this. The file on my PC opens a dialog presentin my local directories, but the file on the server is trying to open the server's root directory structure, hence denied by the server itself. you would probably need to change this line var Shell = new ActiveXObject("Shell.Application"); using a relative value instead to reflect your site's download path, not the server, unless it is your and you don't mind people see the whole structure.