Ilia Choly
Ilia Choly

Reputation: 18557

Detect WebBrowser Control

Is there any way that I could tell if my site is being accessed by an instance of webbrowser control? Would it be possible to identify it by the user agent w/php? Or maybe some javascript hack? Or is it 100% identical to the regular IE from the server side?

Upvotes: 8

Views: 921

Answers (2)

Shahar 'Dawn' Or
Shahar 'Dawn' Or

Reputation: 2961

It seems that a specific error is raised when anything is assigned to window.external. So a check could be something like

const isWebBrowserControl = () => {
  try {
    window.external = window.external
    return false
  } catch (error) {
    if (error.message === 'I don\'t remember this. Some specific error message.') {
      return true
  }
}

This is a potentially "destructive" check, though. But I really don't feel it would cause any problem.

Upvotes: 4

Lux
Lux

Reputation: 18240

Just a stupid idea, but couldn't you just compare window.outerHeight with window.innerHeight, measure the expected difference for IE and if its not then its the WebBrowser Control?

Thats hacky as hell, but could work for most cases. There are also other things you could try to do, things that would work in a certain way in IE but probably won't work in a WebBrowser Control.

For example:

  • download a file
  • open a new window/tab

Upvotes: 3

Related Questions