I have this javascript function that's supposed to open a different div in chrome than in other browsers. The proper div opens in firefox, internet explorer, safari, and chrome, but opera opens the chrome div instead of the other div. Is there a way to stop opera from performing the chrome function?
function Browser() {
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (is_chrome) {
document.getElementById('chrome').style.display = 'block';
document.getElementById('notchrome').style.display = 'none';
}
}
If you read here you can see that you can look for the OPR string to identify Opera.
http://my.opera.com/ODIN/blog/2013/07/15/opera-user-agent-strings-opera-15-and-beyond
For example you can include it in your test like this:
var userAgent = navigator.userAgent.toLowerCase();
var is_chrome = userAgent.indexOf('chrome') > -1 && userAgent.indexOf('opr/') == -1;