0

What I need is just like How can I open a link in the default web browser from an HTA?, but with the restriction that the link sits inside an iframe.

The iframe's loads a page in our server.

Idea: can the iframe's redirect be detected & prevented, so then we'd run code like in https://stackoverflow.com/a/185581/66372. How?

Update 1 To be clear: the problem we're trying to solve is that when the user clicks on any link, it opens in the default browser.

One option similar to mplungjan's answer, is to capture the click event for all links in the iframe's DOM. Is there a more generic option that works at the iframe, document or body level? (and thus also works with delayed loads and any other tricks)

Community
  • 1
  • 1
eglasius
  • 34,909
  • 4
  • 58
  • 105

1 Answers1

2

Something like this, which should be perfectly allowed in an HTA which has elevated rights

window.onload=function() {
  window.frames["iframe_in_this_document"].onload=function() {
    var links = this.document.getElementsByTagName("a");
    for (var i=0;i<links.length;i++) {
      url = links[i].href;
      if (url) links[i].onclick=function() {
        var shell = new ActiveXObject("WScript.Shell");
        shell.run(this.href);
        return false;
      }
   }  
}
mplungjan
  • 134,906
  • 25
  • 152
  • 209
  • Thanks, not exactly what I wanted, but it points a valid solution. Updated the question in case someone knows a more general solution. – eglasius May 07 '13 at 11:52
  • See update. It will trigger on any link loaded in the page onload. Use setTimeout if you want to try and catch delayed load – mplungjan May 07 '13 at 11:55
  • Thanks, that did the trick, took out all delayed loading on the page. I did run into issues trying to hook onload in that way (even tried attachEvent), but only managed to do it by setting it like this in the iframe: onload="iframeLoaded();". Note even this didn't work: onload="iframeLoaded". Maybe the function was supposed to have some argument? (I got no error on it though). – eglasius May 08 '13 at 16:53