简体   繁体   English

从移动网站重定向到桌面网站

[英]Redirect from mobile site to desktop site

I have device detection in place using the following code: 我使用以下代码进行设备检测:

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

if(window.location.hash == "#desktop"){
    // Stay on desktop website
} else {
    window.location = "<?php bloginfo('url'); ?>/m";
} 
}
</script>

This works in that it gets the user back to the desktop version of the website, however, my problem occurs when a user taps a link on the desktop site and then gets redirected to the mobile site. 这可以通过使用户回到网站的桌面版本来工作,但是,当用户点击桌面网站上的链接然后将其重定向到移动网站时,就会发生我的问题。

How can I always append the #desktop to all links if the View desktop link has been clicked? 如果单击了View桌面链接,如何始终将#desktop附加到所有链接? Is this possible? 这可能吗?

well it's just an idea, 嗯,这只是一个主意,

  if(window.location.hash == "#desktop"){
    $(function(){
        $(document).find('a').click(function(e){
           e.preventDefault();
           window.location.replace($(this).attr("href")+"#desktop");
        });
    });
 }

or 要么

   if(window.location.hash == "#desktop"){
     $(function(){
       $(document).find('a').attr("href",$(this).attr()+"#desktop");
     });
   }

I think the best solution is using SESSION on server-side code. 我认为最好的解决方案是在服务器端代码上使用SESSION。

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

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