简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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