[英]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.