[英]redirection based on browser size
我试图根据浏览器的大小将网站查看者重定向到两个页面之一。 我希望常规浏览器(和iPad)停留在查看器正在输入的页面上,例如,这将是:
http://www.testing.com/getstarted.html
但是,如果它们在手机浏览器中,比如说少于700像素,我希望它们重定向到此页面:
http://www.testing.com/mobilegetstarted.html
我已经尝试在头部使用此脚本,但是它不会重定向我的电话-它只是挂起。 谁能帮我解决这个问题?
<script type="text/javascript">
<!--
if (screen.width <= 700) {
document.location = "mobilegetstarted.html";
}
//-->
</script>
我也尝试过通过以下方式添加网址:
http://testing.com/mobilegetstarted.html和
http://www.testing.com/mobilegetstarted.html
但这也不起作用。 有什么线索如何使重定向工作?
加里
document.location是只读的。
您应该使用window.location.assign。
因此,使用:
<script type="text/javascript">
if (screen.width <= 700) {
window.location.assign("mobilegetstarted.html");
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.