Browsing Folders

Discussion in 'JavaScript' started by paradise_wolf, Mar 15, 2007.

  1. #1
    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>
     
    paradise_wolf, Mar 15, 2007 IP
  2. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 :rolleyes:
     
    Your Content, Mar 15, 2007 IP
  3. paradise_wolf

    paradise_wolf Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Tauren

    I am also using IE 6, yet it shows "Error on Page". :confused:

    Is there some setting that I need to change in my IE browser ?
     
    paradise_wolf, Mar 15, 2007 IP
  4. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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):
     
    Your Content, Mar 15, 2007 IP
  5. paradise_wolf

    paradise_wolf Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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 ?
     
    paradise_wolf, Mar 16, 2007 IP
  6. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    Your Content, Mar 16, 2007 IP