0

My webbrowser control displays an intranet site. It was working fine, until the admin changed a setting in iis that forces ie11 to render in Edge mode. Now my webbrowser control comes up with the script error "object doesn't support property or method attachEvent."

Yes, I know attachEvent is deprecated in ie11. No, I do not have control over the webpage code. No, I can't force the admin to change the setting back again.

I tried using registry settings for my application under browser emulation, using all the codes starting with ie9 up through ie10. None of them had any effect.

Can anyone tell me how to force my webbrowser control to render in such a way as to avoid that script error and continue logging in? The call to attachEvent must be called upon successful login, because when I used bad credentials on the login page the error doesn't come up. When my application was working, the page defaulted to ie 9 compatibility. But it seems the admin's IIS setting has nullified that.

StillANewb
  • 11
  • 1
  • First of all you should check if the website shows correctly in Internet Explorer 11. So open IE11 from OS and navigate to the site and see the result. If it is showing correctly it means `WebBrowser` control will show it correctly as well and you can fix the problem by setting browser emulation correctly like described in [this post](http://stackoverflow.com/a/38514446/3110834). – Reza Aghaei Dec 28 '16 at 17:22
  • That does not work. I already tried it, but without the vshost.exe extension. Tried it again per your suggestion, still does not work. It's not so much the display I think that is the problem, but that call to attachEvent in the webpage code is causing a script error that will not let me continue. Prehaps my explanantion wasn't so clear, sorry. – StillANewb Dec 28 '16 at 18:26
  • And it does work with the normal ie11 browser. – StillANewb Dec 28 '16 at 18:28
  • My apologies, sir. This did work with reboot. I also only had it in HK_LM, as I had read about the concept elsewhere and that's the only one it mentioned. Also added it to HK_CURRENT_USER so now it's under both. Probably overkill, but I don't care, it's working. Thanks!! – StillANewb Dec 28 '16 at 18:43

1 Answers1

0

Since you cannot alter the code, I recommend implementing a attachEvent/detachEvent polyfill, like this

HTMLElement.prototype.attachEvent = function(event, cb) {
  var onEventName = "on" + event,
    obj = this;

  if (obj.addEventListener) {
    obj.addEventListener(event, cb, false);

  } else if (obj.attachEvent) {
    obj.attachEvent(onEventName, cb);
  } else {
    var currentEventHandler = obj[onEventName];
    obj[onEventName] = function() {
      if (typeof currentEventHandler === 'function') {
        currentEventHandler.apply(obj, arguments);
      }
      cb.apply(obj, arguments);
    };
  }
};

HTMLElement.prototype.detachEvent = function(event, cb) {
  var onEventName = "on" + event,
    obj = this;

  if (obj.removeEventListener) {
    obj.removeEventListener(event, cb, false);
  } else if (obj.detachEvent) {
    obj.detachEvent(onEventName, cb);
  } else {
    delete obj[onEventName];
  }
};

Here's a working plnkr demonstration (apologies for not using a snippet). I based this code using this old git.

Do note the code is incomplete and not for production, e.g. it is not checking whether HTMLElement, attachEvent, detachEvent exist.

RamblinRose
  • 4,883
  • 2
  • 21
  • 33