如何从其他 url 自动重定向?
How to auto re-direct from other url?
我正在写一个条件自动重定向 url,但它不起作用。我尝试了两种方法:
<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>
正如我之前宣布的那样,这些都不起作用,为什么?
在普通的 Javascript 中,您应该分配值 location 而不是使用方法进行重定向。 replace 方法不会将 url.
的更改保存在历史记录中
window.location = "https://www.organization.org/mobile/index_mobile.htm";
您还在第二种方法中嵌套了两个标签。正确的代码是:
<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>
我正在写一个条件自动重定向 url,但它不起作用。我尝试了两种方法:
<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>
正如我之前宣布的那样,这些都不起作用,为什么?
在普通的 Javascript 中,您应该分配值 location 而不是使用方法进行重定向。 replace 方法不会将 url.
的更改保存在历史记录中window.location = "https://www.organization.org/mobile/index_mobile.htm";
您还在第二种方法中嵌套了两个标签。正确的代码是:
<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>