How can I identify whether the browser is Firefox or Chrome? Basically, I want an application to run only on the specific browser that is registered by a user. For this scenario, I want my application to identify the browser which the user is using, to know whether the application is permitted to run.
I am using java servlet.
I tried a the browser’s local storage, but it can be deleted with no control from my application. If local storage can be used, please let me know how.
(Yes I can get a browser info, but I want to identify a specific machine with a browser from where my application user is permitted to run the application; otherwise, I need to restrict that user from accessing my application.)
Fetch user-agent properties from the HTTP requeste header.
String userAgent=req.getHeader("user-agent");
String browserName = "";
String browserVer = "";
if(userAgent.contains("Chrome")){ //checking if Chrome
String substring=userAgent.substring(userAgent.indexOf("Chrome")).split(" ")[0];
browserName=substring.split("/")[0];
browserVer=substring.split("/")[1];
}
else if(userAgent.contains("Firefox")){ //Checking if Firefox
String substring=userAgent.substring(userAgent.indexOf("Firefox")).split(" ")[0];
browserName=substring.split("/")[0];
browserVer=substring.split("/")[1];
}
httpRequest.getHeader("user-agent")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With