How do I make an angular application work only on a specific browser?

Asked

Viewed 224 times

0

I would like to make my angular application work on a particular browser, and block any other version.

Ex: Work only on Google Chrome 75. And if the user tries to access in a Firefox, Edge, or Chrome in any later or later version, it sends a message to the user who is trying to use this application.

1 answer

4


You can use the property: "Navigator.useragent" to display the browser version. There are other properties as well. Run the code below in a browser to view all of them:

var txt = "";
txt += "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt += "<p>Browser Name: " + navigator.appName + "</p>";
txt += "<p>Browser Version: " + navigator.appVersion + "</p>";
txt += "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt += "<p>Browser Language: " + navigator.language + "</p>";
txt += "<p>Browser Online: " + navigator.onLine + "</p>";
txt += "<p>Platform: " + navigator.platform + "</p>";
txt += "<p>User-agent header: " + navigator.userAgent + "</p>";
alert(txt);
  • This one worked... but I’d have to use an algorithm to get the value from inside the string, right? The string would be this: "5.0 (Windows NT 10.0; Win64; x64) Applewebkit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"

  • 1

    It’s not enough console.log(navigator.appVersion.includes("Chrome/75")); ? Maybe it doesn’t work for all cases but it will surely catch the majority.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.