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?
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin MillerCTOCommented:
Yes, but how are you detecting the browser type ?

Are you doing something like this ?

var userAgent = navigator.userAgent.toLowerCase();
if(/safari/.test(userAgent) )  {
    window.location.href = "anotherPage.html"
}
0
AleksAuthor Commented:
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.
0
Martin MillerCTOCommented:
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.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

AleksAuthor Commented:
Ok. I am testing now ..
0
AleksAuthor Commented:
I tried with Chrome in a PC and it redirected me. Definitely not using Safari here.
0
AleksAuthor Commented:
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?


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));
}

Open in new window

0
AleksAuthor Commented:
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{
   
}

Open in new window

0
Martin MillerCTOCommented:
Your function modified...

function getBrowserName() {
    var name = "Unknown";
   
    if(navigator.userAgent.indexOf("Safari")!=-1){
        name = "Safari";
        window.location.href = "anotherPage.html"
    }
    return name;   // OR you can add the redirect to the calling of the getBrowserName(),
}

if( getBrowserName() == "Safari" ){
    alert("You are using Safari");
}
}
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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 :)
0
AleksAuthor Commented:
Merci!  All good!  Hope you are doing well too. You know we are here 4u
0
AleksAuthor Commented:
This is a variation of the code we used. Works good for what we need.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.