I'm writing for a condizionale auto re-direct url, but it doesn't works. I tried with two methods:
<script>
function mobileDevice()
{
$type = $_SERVER[‘HTTP_USER_AGENT’];
if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)
return true;
else
return false;
}
if(mobileDevice() == true)
header(‘Location: https://www.organization.org/mobile/index_mobile.htm‘);
</script>
<script type="text/javascript">
if (screen.width <= 414) {
document.location = "index.htm";
<script language=javascript>
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("https://www.organization.org/mobile/index_mobile.htm");
}
</script>
}
</script>
In plain Javascript you should assign the value location instead of using method to redirect. replace method won't save in history the change of url.
window.location = "https://www.organization.org/mobile/index_mobile.htm";
Also you are nesting two tags in your second approach. The correct code would be:
<script type="text/javascript">
if (screen.width <= 414) {
document.location = "index.htm";
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("https://www.organization.org/mobile/index_mobile.htm");
}
}
</script>