Issue
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>
and
<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>
As I yet announced, no one of this works, why?
Solution
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>
Answered By - jmtalarn Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.