Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Launching Docs in hta:application

    I've been trying to map out what I want. Being very new to JavaScripting I've really started to struggle so I am hoping someone can help me out here.

    The javascript is being used for an application I orginally wrote as an interface in html. Now I am trying to find ways to get it to work in an hta:application and be a bit more smarter in its handling of how to launch a document.

    Is someone able to please help me out with filling in the code?
    I know its a big ask, any help is appreciated.

    Kat

    <!--
    <script language="JavaScript">

    /* Purpose of the script is to launch a word document an application that can support it's type
    This script is being run in hta:application - When launching direction from an hta it
    displays in browser and looks like gobblygook.
    Q: Is there a way to just have hta handle the launch according to preset file associated with it?
    Ideally this will launch the application and not house the application within the browser like it would in an html
    */



    /* WhereWord = Need to determine if WinWord.exe Exsists in standard install locations
    Current known standard install locations
    var OldWord = C:\\Progra~1\\Micros~1\\Office\\WinWord.exe
    var NewWord = C:\\Progra~1\\Micros~2\\Office10\\WinWord.exe
    Whereword will be set to equal the file path found to exsist (be true).

    I took view because I couldn't find a way to truncate a where exsists
    */


    /* varFilename = Value submitted onClick in document window.
    This value needs to have .doc added to it as a file extension
    */


    /* When WhereWord Exsists the following must be performed
    Launch WinWord varFilename .doc in maximsed state %1
    */


    /* Perform a browse for application to open document in and set that as default for this application
    */


    /* Perform an alert when a suitable .doc application not exsist.
    */

    </script>
    //-->

    In html
    <a href="#" return OnClick="Launch()" value="F01">F01</a>

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you saying that you'd like to open a .doc in Word (if available) and if not, allow the user to browse for an application to open the .doc in (and then save that preference)?

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Anyway...

    It would seem that determining a default application is unnecessary, because the ShellExecute Method of the IShellDispatch2 Object can open a file in its default app...
    For a full explanation of shell objects and methods, go here: Shell Objects for Scripting and Microsoft Visual Basic.
    If you have to determine the default app (for some reason), something like this would work:


    Code:
    <html>
    <head>
    <title>Default Application</title>
    <HTA:APPLICATION />
    <script type="text/jscript">
    function showPath(ext, out)
     {
       out.value = "";
       /(null)/.test("null");
       var wShell = new ActiveXObject("Wscript.Shell");
       try
        {
          /^"([^"]+)"/.test(wShell.RegRead("HKCR\\" + wShell.RegRead("HKCR\\" + ext + "\\") + "\\shell\\open\\command\\"));
        }
       catch(e)
        {
          return alert(e.message);
        }
       var path = RegExp.$1;
       if(path == "null")
         return out.value = "Executable path not available for this type.";
       out.value = path;
       out.select();
     }
    </script>
    <style type="text/css">
    body
     {
       background:threedface;
     }
    fieldset
     {
       padding:1em;
     }
    legend
     {
       color:activeCaption;
     }
    label
     {
       font:caption;
       vertical-align:middle;
     }
    input
     {
       vertical-align:middle;
     }
    </style>
    </head>
    <body>
    <form>
    <fieldset>
      <legend>
        <label> Enter a file extension: </label>
        <input name="ext" size="6" value=".doc">
      </legend>
      <div style="padding-left:9em;margin-top:1em">
      <input type="button" value="Get Path" style="font-weight:bold" onclick="showPath(ext.value, out)">
      </div>
      <label>output: </label>
      <input style="width:100%" name="out" readonly>
    </fieldset>
    </form>
    </body>
    </html>

  • #4
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: neofibril

    Yes, to your first query.

    Now off reading about ShellExecute Method thanks to your pointers due to your second reply.

    Thank you very much for taking the time to answer.

  • #5
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No problem.

    About that example I gave:
    the regular expression is not reliable for many default command strings... (it was just a quick test).

    Also, if the MSDN examples seem vague, feel free to ask for clarification, here.

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why not direct to Word

    neofibril:

    why use Shell commands when ActiveX is wot is usually used? more precisely, why create an ActiveX object to WSH shell and not to Word itself?


  • #7
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because, if Word is not installed, there is no automation object for it, so you'd need to have a try-catch fall-back to the Shell object (and there's no need for the whole Word OLB, just to open a .doc).

    The WScript.Shell object is not required; that was just to demonstrate how one might query the registry for such information.

    The Shell.Application object is part of a seperate interface from WSH, fyi.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •