How can I open a link in the default web browser from an HTA?

后端 未结 2 1736
刺人心
刺人心 2020-11-30 09:15

I\'m working on an application that is implemented as an HTA. I have a series of links that I would like to have open in the system\'s default web browser. Using

相关标签:
2条回答
  • 2020-11-30 09:47

    Create a shell and attempt to run a URL.

    This works for me (save as whatever.hta and execute it) on my system. Clicking on the button opens Google in Firefox:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
      <title>HTA Test</title>
      <hta:application applicationname="HTA Test" scroll="yes" singleinstance="yes">
      <script type="text/javascript">
      function openURL()
      {
          var shell = new ActiveXObject("WScript.Shell");
          shell.run("http://www.google.com");
      }
      </script>
    </head>
    <body>
    
    <input type="button" onclick="openURL()" value="Open Google">
    
    </body>
    </html>
    
    0 讨论(0)
  • 2020-11-30 10:01

    Nope, sadly I believe this is a browser specific implementation that will open new links with target="_blank" within the same browser.

    If you wanted to open it in the default browser, then you would need to interact with the OS, which JavaScript cannot do.

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