【问题标题】:Javascript redirect to mobile URL# Anchor links not supported by the requestJavascript 重定向到移动 URL# 请求不支持锚链接
【发布时间】:2018-09-05 00:53:33
【问题描述】:

如果手机屏幕宽度小于 600 像素,我正在使用下面的 JS 函数将索引页面重定向到另一个页面;
锚链接重定向到索引页面并从其他页面启动的问题没有将任何锚链接传递到用于重定向的新请求 url。
例如: Index.html 重定向到mobindex.html 现在: Index.html#anchor-link 仅重定向到 mobindex.html#anchor 不被包含

    <script>

if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile/i.test(navigator.userAgent)  ) {

if(screen.width >= 600){
    // Stay on desktop website
} else {
    window.location = "http://mywebsite.com/mobindex.html";
}

}
</script>

以前有没有人遇到过这个问题,有什么可能的解决方法? 谢谢。

【问题讨论】:

    标签: javascript mobile url-redirection http-redirect


    【解决方案1】:

    感谢您的帮助... 实际添加 +window.location.hash; 到请求的 url,这样就解决了问题:

    window.location = "http://mywebsite.com/mobindex.html" +window.location.hash;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 2012-07-08
      相关资源
      最近更新 更多