简体   繁体   English

将移动用户重定向到桌面版本

[英]Redirecting a mobile user to a desktop version

I have a Wordpress website that is using device detection to redirect users browsing on their mobile device to a specific page using the following: 我有一个使用设备检测功能的Wordpress网站,它使用以下操作将在移动设备上浏览的用户重定向到特定页面:

<script>
if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile/i.test(navigator.userAgent) ) {
window.location = "176.32.230.17/domain.co.uk/m";
}
</script>

This code currently sits on the homepage template for domain.co.uk. 该代码当前位于domain.co.uk的主页模板上。 Just after the opening body tag. 刚打开身体标签之后。 The detection and redirection works well however, I need to provide a link back to the desktop version of the website on that mobile page. 检测和重定向效果很好,但是,我需要在该移动页面上提供一个指向网站桌面版本的链接。 So just a simple link: 所以只是一个简单的链接:

<a href="http://176.32.230.17/domain.co.uk/?ref=desktop">Link back to desktop website</a>

This works in that it directs the user back to the domain.co.uk address however, because the placement of the detection/redirection code is on the homepage template on domain.co.uk, the user gets redirected back to the mobile version. 这样做是因为它会将用户引导回domain.co.uk地址,因为检测/重定向代码的位置位于domain.co.uk的主页模板上,因此用户将被重定向回移动版本。 How can I fix this? 我怎样才能解决这个问题?

You'll need someway to convey the fact that the user has already been redirected once. 您需要某种方式来传达用户已经被重定向一次的事实。 If you're using PHP, you could have a conditional redirection using a GET variable. 如果您使用的是PHP,则可以使用GET变量进行条件重定向。 If you're just using Javascript, maybe use a cookie. 如果您仅使用Javascript,则可以使用Cookie。 HTML5 also supports some kind of data storage as well, but I'm not familiar with that. HTML5也支持某种数据存储,但是我对此并不熟悉。

EDIT: Actually, you could just tack on a GET variable to the address and not even use PHP. 编辑:实际上,您可以将GET变量附加到地址上,甚至不使用PHP。 Just get the address using window.location.href and see if the variable is set using Javascript only. 只需使用window.location.href获取地址,然后查看是否仅使用Javascript设置了变量。

EDIT2: Too much got put in the comments, so let me put this here. EDIT2:注释中放入太多内容,所以让我将其放在此处。 The link should be changed to: 链接应更改为:

<a href="http://176.32.230.17/domain.co.uk/?ref=desktop#redirected">Link back to desktop website</a>

And the redirection code can be changed to: 重定向代码可以更改为:

<script>
if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile/i.test(navigator.userAgent) &&
        !window.location.href.contains("#redirected") ) {
    window.location = "176.32.230.17/domain.co.uk/m";
}
</script>

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

相关问题 使用Javascript重定向到台式机/移动版的相应页面 - Redirecting to respective page of desktop/mobile version using Javascript 如何在移动网站上创建“桌面版本”链接而不将其重定向到移动网站 - How to create a “Desktop Version” link on mobile website without it redirecting to the mobile site 手动重定向移动桌面版本 - Redirecting mobile-desktop versions manually 通过javascript / php重定向移动/桌面用户 - Redirecting mobile/desktop users through javascript/php 从移动设备共享时,移动博客网站不会重定向到桌面 - Mobile blogger site not redirecting to desktop when shared from mobile 检测移动用户和桌面是否相同 - Detect if mobile user and desktop is same 在加载html内容之前重定向到移动版本 - Redirecting to mobile version before loading html content 通过Mobile访问时加载Mobile Version,否则加载Desktop Version - Load Mobile Version when visited with Mobile otherwise load Desktop Version 书签:对于移动浏览器,重定向到m。*。*;对于桌面浏览器,重定向到www。*。* - Bookmarklet: Redirecting to m.*.* for Mobile Browsers & www.*.* for Desktop Browsers localStorage在台式机上运行,​​但不能在移动设备上运行(iOS版本12.2) - localStorage works on desktop but not mobile (iOS version 12.2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM