简体   繁体   English

从移动设备(wordpress)重定向后,如何留在桌面版网站上

[英]How to stay on Desktop site when redirected from mobile (wordpress)

On my desktop site, I'm using a redirect script "detectmobilebrowser.js" (from detectmobilebrowsers.com) that's working great to redirect mobile users to my mobile site. 在我的桌面站点上,我正在使用重定向脚本“ detectmobilebrowser.js”(来自detectmobilebrowsers.com),该脚本可以很好地将移动用户重定向到我的移动站点。 This code is loaded in the header.php file. 此代码已加载到header.php文件中。

On my mobile site i have a link pointing back to my Desktop site with a URL Parameter 'nomobile'. 在我的移动网站上,我有一个链接指向我的桌面网站,其URL参数为“ nomobile”。 on the desktop site i have the following code (below) that detects the url parameter and does nothing if it exists, or redirects to the mobile site using the .js detection file if the parameter doesn't exist. 在桌面站点上,我具有以下代码(如下),该代码可以检测url参数,如果存在则不执行任何操作,或者如果参数不存在,则使用.js检测文件重定向到移动网站。

My problem is once a user clicks on any link from the home page, i lose the url parameter and the mobile user is redirected back to the mobile site. 我的问题是,一旦用户单击主页上的任何链接,我就会丢失url参数,并且移动用户将被重定向回移动站点。 How can I keep the mobile user on the desktop site without changing hundreds of links on my page to include the url parameter? 如何在不更改页面上的数百个链接以包含url参数的情况下,将移动用户保留在桌面站点上?

    <?php

    if(isset($_GET['nomobile'])){
       echo "";
    } else {
       echo "<script src='http://mywebsite.com/detectmobilebrowser.js'></script>";
    }

    ?>

Don't use a URL parameter to set. 不要使用URL参数进行设置。 Try using a session variable instead. 尝试改用会话变量。

To set the session variable 设置会话变量

$_SESSION['nomobile']=true;

To check if the session is set 检查会话是否已设置

 if(isset($_SESSION['nomobile'])) {
 // do stuff
 }

Alternatively, you could also use cookies instead of session variables, and that should produce the same results. 另外,您也可以使用cookie代替会话变量,这将产生相同的结果。

暂无
暂无

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

相关问题 从移动设备共享时,移动博客网站不会重定向到桌面 - Mobile blogger site not redirecting to desktop when shared from mobile 从移动网站重定向到桌面网站 - Redirect from mobile site to desktop site 如何在调整大小时从 Wordpress 中删除移动菜单但保留桌面菜单? - How to remove mobile menu from Wordpress on resize but keep the desktop one? 移动到桌面重定向并必须留在桌面上 - Mobile To Desktop Redirection and have to Stay on Desktop 让人们从移动网站恢复到桌面版网站 - Letting people revert back to desktop site from mobile site 如何在中预览移动网站 <iframe> 在引导模式下站点的桌面版本中 - How to preview mobile site in <iframe> in desktop version of site in bootstrap modal 如何防止桌面版网站上的图片加载到移动设备上? - How can I prevent images that are on my desktop site from loading on mobile? 如何在移动网站上创建“查看桌面版本”链接,而在解析后又不会循环回到移动版本? - How can I create a “view to desktop version” link on mobile site without it looping back to mobile version when it resolves? 如何在Wordpress网站上移动重定向特定页面 - How to mobile redirect specific pages on Wordpress site 如果一个人在移动设备上,如何使用php或JavaScript将他们重定向到我的移动网站? - How do I use php or JavaScript to make a person be redirected to my mobile site if they are on a mobile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM