Aleks
asked on
Redirect if user is using Safari
Using Classic ASP, is there a reliable way to redirect a user to another page on load if the user is using Safari?
ASKER
Currently I don't have a script to detect the browser, we support most browsers, just not Safari.
Will the script above help redirect if the user is using Safari ONLY?
I have read that sometimes redirects will redirect when user is using Chrome, I just want to make sure this is not the case.
Will the script above help redirect if the user is using Safari ONLY?
I have read that sometimes redirects will redirect when user is using Chrome, I just want to make sure this is not the case.
The javascript snippet is locking in on the User Agent identifier text string, Safari converted to lowercase text, as safari. I don't think Chrome will give out Safari emulation without modification.
ASKER
Ok. I am testing now ..
ASKER
I tried with Chrome in a PC and it redirected me. Definitely not using Safari here.
ASKER
I found this script which seems to work fine, how can I change it so that it redirects when browser is Safari ?
And remove the alerts when its something else?
And remove the alerts when its something else?
function getBrowserName() {
var name = "Unknown";
if(navigator.userAgent.indexOf("MSIE")!=-1){
name = "MSIE";
}
else if(navigator.userAgent.indexOf("Firefox")!=-1){
name = "Firefox";
}
else if(navigator.userAgent.indexOf("Opera")!=-1){
name = "Opera";
}
else if(navigator.userAgent.indexOf("Chrome") != -1){
name = "Chrome";
}
else if(navigator.userAgent.indexOf("Safari")!=-1){
name = "Safari";
}
return name;
}
if( getBrowserName() == "Safari" ){
alert("You are using Safari");
}else{
alert("You are surfing on " + getBrowserName(name));
}
ASKER
This worked:
function getBrowserName() {
var name = "Unknown";
if(navigator.userAgent.indexOf("MSIE")!=-1){
name = "MSIE";
}
else if(navigator.userAgent.indexOf("Firefox")!=-1){
name = "Firefox";
}
else if(navigator.userAgent.indexOf("Opera")!=-1){
name = "Opera";
}
else if(navigator.userAgent.indexOf("Chrome") != -1){
name = "Chrome";
}
else if(navigator.userAgent.indexOf("Safari")!=-1){
window.location.href = "notsupported.html"
}
return name;
}
if( getBrowserName() == "Safari" ){
window.location.href = "notsupported.html";
}else{
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no points please, just offering up a suggestion...
if you're ok with paying for something very reliable, then you may want to check out https://51degrees.com/device-detection, which is an online service that does browser detection (among MANY other things like browser details, not just the UserAgent string, which can change as new versions of browsers are released, screen resolution, and yes, these pieces of data can be obtained without the use of 3rd party services, but this makes it so much easier). I had to implement it for my job and it was a lot easier to use than I expected.
Hope all is well with you and the family :)
if you're ok with paying for something very reliable, then you may want to check out https://51degrees.com/device-detection, which is an online service that does browser detection (among MANY other things like browser details, not just the UserAgent string, which can change as new versions of browsers are released, screen resolution, and yes, these pieces of data can be obtained without the use of 3rd party services, but this makes it so much easier). I had to implement it for my job and it was a lot easier to use than I expected.
Hope all is well with you and the family :)
ASKER
Merci! All good! Hope you are doing well too. You know we are here 4u
ASKER
This is a variation of the code we used. Works good for what we need.
Are you doing something like this ?
var userAgent = navigator.userAgent.toLowe
if(/safari/.test(userAgent
window.location.href = "anotherPage.html"
}