简体   繁体   English

让人们从移动网站恢复到桌面版网站

[英]Letting people revert back to desktop site from mobile site

My website will revert visitors to a seperate mobile site, this seems fairly simple after reading a few guides online. 我的网站将访问者恢复到一个单独的移动网站,在线阅读一些指南后,这似乎相当简单。

However, I would like people to be able to click a link on the mobile site which will then take them to the desktop site. 但是,我希望人们能够点击移动网站上的链接,然后将其带到桌面网站。

The problem I see is that if I link back to the desktop site it will just redirect them back if they are on mobile? 我看到的问题是,如果我链接回桌面网站,它只会重定向它们,如果它们在移动设备上?

How can I get around this? 我怎么能绕过这个?

Really you want to be doing this sort of thing server-side, not client-side. 真的,你想做服务器端的这种事情,而不是客户端。 The issue is you're forcing a mobile user (on a potentially bad connection) to download your whole desktop site first (which might be over 1MB), just for the javascript redirect to take effect. 问题是你是强迫移动用户(在可能很糟糕的连接上)首先下载你的整个桌面站点(可能超过1MB),只是为了使javascript重定向生效。

By that point, your mobile visitor may have lost patience and left already. 到那时,您的移动访问者可能已经失去了耐心而已经离开了。

I blogged about the process here: http://www.9xb.com/blog-2012-08-6-common-pitfalls-when-deploying-a-mobile-site-and-how-they-can-be-avoided/ - if you jump to the bottom of the article, you'll see a flow diagram that maps out the whole process. 我在这里写了博客: http//www.9xb.com/blog-2012-08-6-common-pitfalls-when-deploying-a-mobile-site-and-how-they-can-be-avoided / - 如果你跳到文章的底部,你会看到一个映射整个过程的流程图。 This particular method uses cookies, but it could be adapted. 这种特殊方法使用cookie,但可以进行调整。 The beauty of this flow diagram is that it is language independent - you can develop it in any server side programming flavour. 这个流程图的美妙之处在于它与语言无关 - 您可以在任何服务器端编程风格中进行开发。

For your convenience, I've included the flow diagram below (although I strongly recommend you give the article a read): 为了您的方便,我已经包含了下面的流程图(虽然我强烈建议您阅读本文):

http://www.9xb.com/wordpress/wp-content/uploads/2012/08/mobile-deployment-small.png http://www.9xb.com/wordpress/wp-content/uploads/2012/08/mobile-deployment-small.png

The alternative to all of that work, would be to develop a mobile-first responsive site. 所有这些工作的替代方案是开发一个移动优先响应站点。 Not knowing your circumstances, I'll leave it at that - it's not always appropriate in every single scenario. 不知道你的情况,我会把它留在那里 - 它并不总是适合每一个场景。

Make the redirect-to-mobile optional (ie a link at the top of the desktop page), or put the mobile redirect only on the initial entry point, ie mydomain.com . 使重定向到移动可选(即桌面顶部的链接),或将移动重定向仅放在初始入口点,即mydomain.com If they go to mydomain.com/index.html , then don't redirect. 如果他们转到mydomain.com/index.html ,则不要重定向。 That way your 'back to desktop' link can be simply a normal link to index.html , from index_mobile.html or wherever you send them for their mobile experience. 这样,您的“返回桌面”链接可以是index.html的常规链接,可以是index_mobile.html ,也可以是您发送移动体验的地方。

Personally, I would much rather the layout was fluid enough to fit whichever browser anyway, then there is no problem to begin with. 就个人而言,我更倾向于布局流畅到足以适合任何浏览器,然后开始没有问题。 Remember, there are now tablets of various sizes to muddy the mobile browsing waters. 请记住,现在有各种尺寸的平板电脑可以混淆移动浏览水域。

Unfortunately you cannot check for the referrer after window.location change. 遗憾的是,在window.location更改后,您无法检查引用者。 But you can add a hashtag and then check for it. 但是您可以添加一个#标签然后检查它。

if(window.location.hash == "#stayHereDude"){
    // do nothing, or whatever
} else {
    window.location = "mobile/index.html";
}

Then, you'ld make a link to /index.html#stayHereDude on the mobile page. 然后,您将在移动页面上链接到/index.html#stayHereDude。

On your home page that makes the mobile redirect, you'll want to check for something in the href that marks them as having coming from the mobile site. 在您的主页上进行移动重定向,您需要检查href中的某些内容,这些内容标记为来自移动网站。 In my case I've used a link to the home page from the mobile site with a ?m=0 at the end of it. 在我的情况下,我使用了移动网站主页的链接,结尾处有一个?m = 0。 For example: http://www.yoursite.com/?m=0 例如: http//www.yoursite.com/?m = 0

Then you check before the redirect on the home page for that m=0 in the href. 然后在主页上的重定向之前检查href中的m = 0。 if it's there, don't redirect, if it isn't, redirect to mobile. 如果它在那里,不要重定向,如果不是,重定向到移动。

if (window.location.href.match("m=0")) { 
} else {
    window.location = "http://www.yoursite.com/mobilesite";
}

This works if you're only redirecting from a single page to your mobile site. 如果您只是从一个页面重定向到您的移动网站,则此方法有效。

You can use Cookies, Session or Local Storage such that when a user clicks on "go to desktop site", it sets a value. 您可以使用Cookie,会话或本地存储,以便当用户点击“转到桌面网站”时,它会设置一个值。

Let's say you set the name to be "mobileOff" and the value set to "1" or "true" when a user on a mobile phone clicks on "Go to Desktop Site". 假设您将手机上的用户点击“转到桌面版网站”,将名称设置为“mobileOff”,将值设置为“1”或“true”。 Then, wherever you're doing your mobile check, add a conditional to check for the mobileOff in the user's cookie/session/localStorage, if it's set to true, bypass the automatic mobile redirect, otherwise, load the main desktop site. 然后,在您进行移动检查的任何地方,添加条件以检查用户的cookie / session / localStorage中的mobileOff,如果设置为true,则绕过自动移动重定向,否则,加载主桌面站点。

you should combine user agent method to detect device clubbed with query string to this sort of functionality. 你应该结合用户代理方法来检测设备俱乐部与查询字符串到这种功能。 so lets assume your link is 所以我们假设您的链接是

site/default.aspx

if some one hits this page check the user agent and give in the response the appropriate site or event better if the device detected if a mobile device simply redirect to m.yourdomain.com/site/default.aspx 如果有人点击此页面,请检查用户代理并在响应中提供相应的站点或事件,如果设备检测到移动设备是否只是重定向到m.yourdomain.com/site/default.aspx
but if some one hits the page site/default.aspx?type=desktop then override the behaviour of checking the useragent and render the desktop site. 但如果有人点击页面site / default.aspx?type = desktop,则覆盖检查useragent并呈现桌面站点的行为。

never ever you should first load the desktop site and then via javascript reditect to a mobile site. 从来没有你应该首先加载桌面网站,然后通过javascript reditect到移动网站。 do this using user agents server side. 使用用户代理服务器端执行此操作。

Static 静态的

/site/index.html
/site/mobile/index.html

Then you can use a range of things. 然后你可以使用一系列的东西。

  1. Cookies 饼干
  2. Session States 会议国家
  3. User Logged in and Preference Settings (even database saved) 用户登录和首选项设置(甚至保存数据库)

If you're using a static site - becomes more difficult as it gets messy with JavaScript redirects and two many duplicate pages. 如果您使用的是静态网站 - 由于JavaScript重定向和两个重复页面混乱而变得更加困难。 Post your code and tell us your how you are currently doing your setup and I will update my solution. 发布您的代码并告诉我们您目前如何进行设置,我将更新我的解决方案。

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

相关问题 从移动网站重定向到桌面网站 - Redirect from mobile site to desktop site 从移动设备共享时,移动博客网站不会重定向到桌面 - Mobile blogger site not redirecting to desktop when shared from mobile 阻止人们返回现场? - Block people from returning to site? 从移动设备(wordpress)重定向后,如何留在桌面版网站上 - How to stay on Desktop site when redirected from mobile (wordpress) 响应网站上的单独桌面和移动jQuery功能 - Separate desktop and mobile jQuery functions on a responsive site 我的网站在移动设备上显示为桌面 - My site is showing up as desktop on mobile 强制桌面浏览器打开移动网站 - Force desktop browser to open mobile site 如何在中预览移动网站 <iframe> 在引导模式下站点的桌面版本中 - How to preview mobile site in <iframe> in desktop version of site in bootstrap modal Cypress runner 加载移动站点而不是桌面站点 - Cypress runner loading mobile site instead of desktop site 如何在移动网站上创建“查看桌面版本”链接,而在解析后又不会循环回到移动版本? - How can I create a “view to desktop version” link on mobile site without it looping back to mobile version when it resolves?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM