I have a situation where I am looking to make a script when the user loads the index.html file, to perform a browser check and to see if the user is using only Google Chrome. And if the user is using other browsers, to have an error like "sorry, you have to use google chrome". I have the code below:
<html>
.....
<body onload="load()">
...content
<script type="text/javascript">
function load()
{
if (navigator.userAgent.search("MSIE") >= 0)
{
document.write('This tool is required to be used only by Google Chrome.');
}
else if (navigator.userAgent.search("Edge") >= 0)
{
document.write('This tool is required to be used only by Google Chrome.');
}
else if (navigator.userAgent.search("Chrome") >= 0)
{
var url = document.URL,
index = url.indexOf("#"),
hash = index != -1 ? url.substring(index+1) : "";
if(hash === "")
{
location.hash = "#default";
}
else
{
var tabInfo = chrome.tabs.getCurrentTab();
var id = tabInfo.tabId;
window.location = id;
}
}
else if (navigator.userAgent.search("Firefox") >= 0)
{
document.write('This tool is required to be used only by Google Chrome.');
}
else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0)
{
document.write('This tool is required to be used only by Google Chrome.');
}
else if (navigator.userAgent.search("Opera") >= 0)
{
document.write('This tool is required to be used only by Google Chrome.');
}
else
{
document.write('This tool is required to be used only by Google Chrome.');
}
}
</body>
The code itself works for every other browser, except IE(Internet explorer). The version of the IE is 11.3930.14393.0.
Can you guys help me out with this please?