I would like to make a button (with a url) dynamic to what the user's browser is using. If the user is using Chrome, then the link will open in a new tab; however if the user is using IE, the link should open in Chrome.
I am unable to make the following code work in Chrome but this works in IE 9.
I have gotten helpful codes from some other posts.
The following will determine/ check which browser the user is on:
function getInternetExplorerVersion()
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
The above snippet works fine. My code below works seamlessly in IE but not in Chrome.
<input type="button" onclick="openURL()" value="Open Google">
<script>
function openURL()
{
var ver = getInternetExplorerVersion();
var shell = new ActiveXObject("WScript.Shell");
if ( ver = -1 )
shell.run("Chrome www.google.com");
else
window.open('www.google.com','_blank');
}
</script>