Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if browser is vbscript capable?

I was hoping i could use modernizer (or similar) to determine if a browser was capable of running vbscript. It doesn't look like i can.

Recently IE11 has modified the user-agent removing MSIE and replacing with 'Trident'. This was done to make IE look more like other browsers in compliance with html specs.

I have a number of old sites that require the browser to support vbscript. I am looking for a way to determine how I can determine if the browser supports vbscript. A number of these sites use classic asp which makes it more difficult.

Ideas? ty Right now, I am thinking of using javascript to evaluate the user agent and if it contains msie then we can assume it does support vbscript.

like image 508
David Avatar asked Mar 30 '14 21:03

David


2 Answers

The shortest way I was able to do this was as follows (might be a cleaner way, but I don't know VBScript, I just know Modernizr).

var supportsVb = (function() {
  var supports = false;
  var vb = document.createElement('script');
  vb.type="text/vbscript";
  try {
    vb.innerText="Err.Raise";
  } catch (e) {
    supports = true;
  }
  return supports
})()

The idea being that only vbscript engines will raise an error for that syntax.

It can be used like this:

if (supportsVb) {
    // Make a vbscript call
} else {
    // Make a javascript call
}
like image 135
Patrick Avatar answered Sep 25 '22 15:09

Patrick


See progressive enhancement.

Build the page to give then "VBScript is not supported" experience.

Then add VBScript to transform it (adding and removing DOM elements) to the "VBScript is supported" version.

like image 42
Quentin Avatar answered Sep 25 '22 15:09

Quentin