Reputation: 25
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?
Upvotes: 1
Views: 10676
Reputation:
My smart code is:
var uagent = navigator.userAgent.toLowerCase();
if(/safari/.test(uagent) && !/chrome/.test(uagent))
{
window.location.href = "elsewhere.html"
}
Upvotes: 3
Reputation: 3039
Try this:
if(typeof navigator.vendor!='undefined' && navigator.vendor.toLowerCase().indexOf('apple')!=-1){
// redirection
}
Upvotes: 0
Reputation:
Try this simple code:
if(/safari/.test(navigator.userAgent.toLowerCase()) && !/chrome/.test(navigator.userAgent.toLowerCase()))
{
window.location.href = "elsewhere.html"
}
Upvotes: 1
Reputation: 25
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>
Upvotes: 0