1

I have a problem about using the following code to check browser

view =(
            typeof self !== "undefined" && self ||
            typeof window !== "undefined" && window ||
            this.content
        ); 
is_safari = /constructor/i.test(view.HTMLElement) || view.safari,
is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent),

The upper code snippet is from FileSaver.js, and the problem is what is the meaning of /constructor/i.test, it seems the javascipt api not include this function. Is there anyone know about that, thanks a lot.

abramhum
  • 443
  • 2
  • 8
  • 20
  • Possible duplicate of [How to detect Safari, Chrome, IE, Firefox and Opera browser?](https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser) – Waleed Iqbal Jan 30 '18 at 10:09
  • If you test it with safari put `alert(view.HTMLElement);` and if you use chrome put `alert(navigator.userAgent);` after `view = (...)` Then tell us what alert shows to you. – Masoud Keshavarz Jan 30 '18 at 10:20
  • I use console.info(view.HTMLElement); and I got "function HTMLElement() { [native code] }"; and then navigator.userAgent, I got "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36 OPR/36.0.213"; thanks – abramhum Jan 31 '18 at 12:38

1 Answers1

3

It is standard JavaScript.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • `test is a method found on regular expression objects` do you mean it looks for test into `/pattern/`? If no could you provide a very simple example about it please? – Masoud Keshavarz Jan 30 '18 at 10:09
  • No. There are examples in the documentation I linked to (and in the code in the question!) – Quentin Jan 30 '18 at 10:10