What are some methods to link to and run a local .exe file in a local browser

前端 未结 3 1067
离开以前
离开以前 2020-12-20 08:47

I am trying to use html/javascript to run a local .exe file in a local browser. The .exe file will generate asci text and I have it programed to encapsulate the text in htm

相关标签:
3条回答
  • 2020-12-20 09:11

    Would it make it easier if, rather than running the browser and application separately, maybe you had an application you run which contains a webbrowser - then talking between them is easier because you can get access to the inner workings of the browser ... Just a thought.

    0 讨论(0)
  • 2020-12-20 09:26

    There are two solutions I can think of.

    1) In IE - Use WScript.Shell and do whatever you need in Windows.

    In IE - Here is a sample to open notepad. You place your executable there and then have it write it's file and then read the file.

     <script>
     function go() {
       w = new ActiveXObject("WScript.Shell");
       w.run('notepad.exe');
       return true;
       }
    
     </script>
    
     <form>
       Run Notepad (Window with explorer only)
         <input type="button" value="Go" 
         onClick="return go()">
    </FORM>
    

    Here is a sample for reading from a file

    // define constants
    // Note: if a file exists, using forWriting will set
    // the contents of the file to zero before writing to
    // it. 
    var forReading = 1, forWriting = 2, forAppending = 8;
    // define array to store lines. 
    rline = new Array();
    // Create the object 
    fs = new ActiveXObject("Scripting.FileSystemObject");
    f = fs.GetFile("test.txt");
    // Open the file 
    is = f.OpenAsTextStream( forReading, 0 );
    // start and continue to read until we hit
    // the end of the file. 
    var count = 0;
    while( !is.AtEndOfStream ){
       rline[count] = is.ReadLine();
       count++;
    }
    // Close the stream 
    is.Close();
    // Place the contents of the array into 
    // a variable. 
    var msg = "";
    for(i = 0; i < rline.length; i++){
       msg += rline[i] + "\n";
    }
    // Give the users something to talk about. 
    
    WScript.Echo( msg );
    

    2) Create a signed Java Applet and talk to it through JavaScript

    Maybe there is a way to talk to a Java Applet from the Javascript and then have the Applet do the work - It would probably need to be signed.

    0 讨论(0)
  • 2020-12-20 09:28

    The short answer: you can't do it without writing a browser plug-in of some sort. Probably there's a simpler way of doing what you want.

    0 讨论(0)
提交回复
热议问题