Javascript 基于浏览器大小的重定向

Javascript 基于浏览器大小的重定向,javascript,url-redirection,Javascript,Url Redirection,我正在尝试根据浏览器大小将我的网站浏览者重新定向到两个页面中的一个。我希望常规浏览器(和iPad)停留在观众进入的页面上,例如: http://www.testing.com/getstarted.html 但是如果它们在手机浏览器上,比如说小于700像素,我希望它们重新定向到这个页面: http://www.testing.com/mobilegetstarted.html 我尝试在头部区域使用此脚本,但它没有重定向我的手机-它只是挂起。谁能帮我修一下吗 <script type

我正在尝试根据浏览器大小将我的网站浏览者重新定向到两个页面中的一个。我希望常规浏览器(和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>
但这也不行。有什么线索可以帮助你重新指导工作吗


Gary

文档。位置为只读

您应该使用window.location.assign

因此,请使用:

<script type="text/javascript">
if (screen.width <= 700) {
    window.location.assign("mobilegetstarted.html");
}
</script>

如果(屏幕宽度
<script type="text/javascript">
if (screen.width <= 700) {
    window.location.assign("mobilegetstarted.html");
}
</script>