Issue
I want to create code which will auto get the user's browser version and check it , if it was for example less than 50 popup alert which say "You can not access to this website(Update your Browser)" and open error page.
Solution
function get_version() {
let ua = navigator.userAgent,
tem,
M =
ua.match(
/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i
) || [];
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return { name: "IE", version: tem[1] || "" };
}
if (M[1] === "Chrome") {
tem = ua.match(/\bOPR|Edge\/(\d+)/);
if (tem != null) {
return { name: "Opera", version: tem[1] };
}
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, "-?"];
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
M.splice(1, 1, tem[1]);
}
return {
name: M[0],
version: M[1],
};
}
let browser = get_version();
// you can use these two in anywhere
console.log(browser.name,browser.version)
Answered By - shay232
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.