简体   繁体   English

JavaScript重定向到移动URL#请求不支持的锚链接

[英]Javascript redirect to mobile URL# Anchor links not supported by the request

Am using JS function below in order to redirect index page to another one if mobile screen width is less than 600 px; 如果移动屏幕宽度小于600像素,则在下面使用JS函数将索引页重定向到另一页;
The problem that anchor links redirecting to the index pages and being initiated from other pages are not passing any anchor links to the new requested url used for the redirection. 锚链接重定向到索引页面并从其他页面启动的问题没有将任何锚链接传递给用于重定向的新请求的URL。
For example : Index.html redirects to mobindex.html Now For: Index.html #anchor-link redirecting just to mobindex.html #anchor not being included . 例如: 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>

Did anyone had this issue before and what possible fix? 有人以前有这个问题吗?有什么可能的解决方法? Thanks. 谢谢。

Thank you for any help... Actually Adding +window.location.hash; 谢谢您的帮助...实际上正在添加+window.location.hash; to the requested url, in that way solved problem: 到所请求的URL,以这种方式解决了问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM