I am using this script to detect the string “safari” in the user agent header which then redirects you to “android.html” how would I change the code to make it so it redirects if the user agent header does NOT contain “safari”?
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("safari") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
window.location = 'android.html';
}
EDIT:
Here is my revised code. Does this make sense? It first detects whether the device is android or not then it redirects if it is a safari browser.
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
var isSafari = ua.indexOf("safari") == -1;
if(isAndroid) {
if(isSafari) {
window.location = 'android.html';
}
}
Just to go with the name of the variable, change the condition from
> -1to== -1.