1

I currently use this script to detect and redirect a page when safari is used

if(/safari/.test(navigator.userAgent.toLowerCase())) {
    window.location.href = "elsewhere.html"
}

however it redirects in safari and chrome.

how do I make it redirect only in safari only?

Bojangles
  • 99,427
  • 50
  • 170
  • 208
xeflip
  • 25
  • 3
  • 10
  • Can you post a link to the site? – GSaunders Jan 29 '14 at 18:12
  • 1
    Check: http://stackoverflow.com/questions/7944460/detect-safari-browser – Skwal Jan 29 '14 at 18:13
  • _“I currently use this script to detect and redirect a page when safari is used”_ – what for? – CBroe Jan 29 '14 at 18:13
  • hi i currently cant post the link as this is private. but the problem im facing is that it redirects on both safari and chrome. how do i only detect and redirect in safari only – xeflip Jan 29 '14 at 18:13
  • @CBroe i want to show my users a different page when they use safari as i have some content that does not work in safari – xeflip Jan 29 '14 at 18:14
  • 6
    Maybe you should fix that content instead of trying to detect Safari? – Bojangles Jan 29 '14 at 18:16
  • hmm from what i see at http://stackoverflow.com/questions/7944460/detect-safari-browser it only detects safari. but how do i redirect? @Skwal – xeflip Jan 29 '14 at 18:16
  • ok managed to get it to work! thanks for your help! – xeflip Jan 29 '14 at 18:28
  • @xeflip Then add an answer yourself to this question showing how you solved it, so future users will learn from you! – This company is turning evil. Jan 29 '14 at 19:02
  • I hope the page you redirect to is the download page for Chrome or FireFox. Because Safari should not be considered a browser in the first place... I can even fix problems in IE8, but this piece of crap is another story... – user2173353 Mar 20 '17 at 11:23

4 Answers4

3

My smart code is:

var uagent = navigator.userAgent.toLowerCase();
if(/safari/.test(uagent) && !/chrome/.test(uagent))
{
    window.location.href = "elsewhere.html"
}
1

Try this simple code:

if(/safari/.test(navigator.userAgent.toLowerCase()) && !/chrome/.test(navigator.userAgent.toLowerCase()))
{
    window.location.href = "elsewhere.html"
}
0

Just put this script into your header. It should detect and redirect safari only. Just change window.location.href = "somewhere.html" to the url you want to redirect safari users.

<script>
var ua = navigator.userAgent.toLowerCase(); 
 if (ua.indexOf('safari')!=-1){ 
   if(ua.indexOf('chrome')  > -1){

   }else{
    window.location.href = "somewhere.html" // saf
   }
  }

</script>
xeflip
  • 25
  • 3
  • 10
0

Try this:

if(typeof navigator.vendor!='undefined' && navigator.vendor.toLowerCase().indexOf('apple')!=-1){
 // redirection
}
Ashish Kumar
  • 2,991
  • 3
  • 18
  • 27