12

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 <a href="url" target="_blank"> opens the link in IE regardless of the default browser.

Is there a way to use the default browser? Using JavaScript is an option.

2 Answers 2

30

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>
3
  • 6
    This only works when implemented in IE. Not in Chrome or Firefox.
    – Siyah
    May 18, 2015 at 9:24
  • 2
    @Siyah HTAs are run using the IE engine: en.wikipedia.org/wiki/HTML_Application#Execution May 18, 2015 at 10:13
  • I want to download a file that i have created using blob. How to do it in HTA. It is working fine in chrome. But gives error "Access Denied" in HTA Oct 13, 2015 at 5:18
-2

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.

1
  • 3
    JScript inside an HTA gets to run in the "Local" security zone, so it can access a lot more of the OS, including ActiveX.
    – ephemient
    Oct 9, 2008 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.