-1

I'm trying to create a javascript code only for the edge and internet explorer or even a 10. I only find information for internet explorer

        var isIE = document.body.style.msTouchAction !== undefined;
if(isIE ){// stuff }
DenisMasot
  • 555
  • 4
  • 9
  • 18
  • 1
    This sounds like an [XY Problem](https://meta.stackexchange.com/q/66377/153542). **Why** do you want to detect IE and Edge? – zzzzBov Sep 03 '17 at 19:21
  • Possible duplicate of [How to target Windows 10 Edge browser with javascript](https://stackoverflow.com/questions/31721250/how-to-target-windows-10-edge-browser-with-javascript) – Rob Sep 03 '17 at 19:22

2 Answers2

1

Browser Hacks shows var isIE = window.navigator.msPointerEnabled; as a solution.

And actually, it shows what you have as well. According to them, it works for IE10+ and Edge.

spanky
  • 2,648
  • 5
  • 9
0

I think what you are looking for is described in a previous answer: https://stackoverflow.com/a/32938396/1501985.

To quote the link (in short):

Using a parser library

# https://github.com/faisalman/ua-parser-js.

var parser = new UAParser();
var result = parser.getResult();

var name = result.browser.name;
var version = result.browser.version;

Raw Javascript approach

# Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) \
# Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

window.navigator.userAgent.indexOf("Edge") > -1
  • 1
    I think the idea is to avoid user agent sniffing since it can be spoofed. – spanky Sep 03 '17 at 19:19
  • I understand how that can be a concern, but I don't read this as a constraint by the original poster. In addition, anything, which relies on the client as master of data, can be spoofed by the user. – Andreas Christiansen Sep 03 '17 at 19:22