Please forgive me if this is a recurring theme or nightmare, but I searched the forum and couldn't find an answer so I brought up a new topic.
Problem: I need to detect user's browser so I can display a "bookmark this page" link that works in IE and displays a browser specific message to Mac + PC users.
I have most PC browsers working correctly except Opera, so I would greatly appreciate it if you could take a look at what I am doing and reply with a fix.
Code:
function bookmarkThisPage(){
// copyright Brite Inc.
var browser=navigator.userAgent.toLowerCase();
var os=navigator.platform.toLowerCase();
var opera=(window.opera ? true : false);
if ((browser.indexOf("opera") != -1) && (opera("true"))) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+OPERA does not support this function. Please click OK then press CTRL+T on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+OPERA does not support this function. Please click OK then press APPLE+T on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("msie") != -1) {
if (os.indexOf("win") != -1) {
window.external.AddFavorite(self.location.href,document.title)
}
if (os.indexOf("mac") != -1) {
window.external.AddFavorite(self.location.href,document.title)
}
}
if (browser.indexOf("netscape") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+NETSCAPE does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+NETSCAPE does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("firefox") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+FIREFOX does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+FIREFOX does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("safari") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+SAFARI does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+SAFARI does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
}
Problem: I need to detect user's browser so I can display a "bookmark this page" link that works in IE and displays a browser specific message to Mac + PC users.
I have most PC browsers working correctly except Opera, so I would greatly appreciate it if you could take a look at what I am doing and reply with a fix.
Code:
function bookmarkThisPage(){
// copyright Brite Inc.
var browser=navigator.userAgent.toLowerCase();
var os=navigator.platform.toLowerCase();
var opera=(window.opera ? true : false);
if ((browser.indexOf("opera") != -1) && (opera("true"))) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+OPERA does not support this function. Please click OK then press CTRL+T on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+OPERA does not support this function. Please click OK then press APPLE+T on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("msie") != -1) {
if (os.indexOf("win") != -1) {
window.external.AddFavorite(self.location.href,document.title)
}
if (os.indexOf("mac") != -1) {
window.external.AddFavorite(self.location.href,document.title)
}
}
if (browser.indexOf("netscape") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+NETSCAPE does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+NETSCAPE does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("firefox") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+FIREFOX does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+FIREFOX does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
if (browser.indexOf("safari") != -1) {
if (os.indexOf("win") != -1) {
window.alert('Your browser PC+SAFARI does not support this function. Please click OK then press CTRL+D on your keyboard to bookmark this page.');
}
if (os.indexOf("mac") != -1) {
window.alert('Your browser MAC+SAFARI does not support this function. Please click OK then press APPLE+D on your keyboard to bookmark this page.');
}
}
}