While on a mobile device, click on "View desktop site" then return to the mobile version of the site by clicking "View mobile site". The cookie does not persist and you get redirected back to the desktop site on the next page you click.

To clarify, the first page you land on is the mobile version of the site. Clicking another page will return you to the desktop version of that page.

I'm using these two blocks inside the Mobile Tools Block Message Options.

<a href="!desktop_url">View desktop site</a>
<a href="!mobile_url">View mobile site</a>

When I'm on a mobile device my url is redirected to the "m.domain.com" mobile site and I see the mobile site.

Then:
1) Click View desktop site
<a href="!desktop_url">View desktop site</a>
cookie is created: (mt_device=desktop, domain.com)

2) Browse around the desktop site - it works! I am on a mobile device and I see the desktop site

3) Click View mobile site
<a href="!mobile_url">View mobile site</a>
cookie is created: (mt_device=mobile, m.domain.com)

4) Browse around mobile site - it does not work! -- The first page I land on is the mobile version, but when I click to a different page, it reverts back to the desktop version of that page. :(

final cookies:
(mt_device=desktop, domain.com)
(mt_device=mobile, m.domain.com)

~~~~~~~~~~~~~~~~~~~

I found that this code work the best for both a desktop user and a mobile user:

<a href="!desktop_url">View desktop site</a>
<a href="?device=mobile">View mobile site</a>

EXCEPTION: if I'm on a link that already has a query, then this relative url would not work--
domain.com/article?page=1?device=mobile

It would have to detect a query and change it to:
domain.com/article?page=1&device=mobile

When I am on a mobile device my url is redirected to the "m.domain.com" mobile site and I see the mobile site:

1) Click View desktop site
<a href="!desktop_url">View desktop site</a>
cookie is created: (mt_device=desktop, domain.com)

2) Browse around the desktop site - it works! I am on a mobile device and I see the desktop site :)

3) Click View mobile site
<a href="?device=mobile">View mobile site</a>
cookie is created: (mt_device=mobile, m.domain.com)
AND cookie is altered: (mt_device=mobile, domain.com)

4) Browse around mobile site - it works!

final cookies:
(mt_device=mobile, domain.com)
(mt_device=mobile, m.domain.com)

The reason why "?device=mobile" works is because it altered this cookie: (mt_device=mobile, domain.com), unlike "!mobile_url". Compare Step 3 on both use cases. I believe that may be the fix. Any ideas, suggestions, help is greatly appreciated.

Comments

Oh on an update, I found this relative link
<a href="?device=mobile">View mobile site</a>

Changes this url
domain.com/article?page=1?device=mobile

to:
domain.com/article?device=mobile

So you lose the page you're on. Don't know how it would handle search queries. Either way not great. hm.

Would you be so kind as to explain how this link is used? For example, I assume (perhaps mistakenly) that in this line of code:

<a href="!desktop_url">View desktop site</a>

This bit -- desktop_url -- is to be replaced with the URL name of your non-mobile website.

But when I do that and place this line of code in a page or block, set to full html for input format, it says page not found.

Am I going about this the right way? Thank you!

Assigned:Unassigned» twom
Status:Active» Needs review

Hi all,

I could not replay the exact scenario presented by @dlin.

I changed the creation of the url presented in the !desktop_url and !mobile_url block. Currently the path is:

- /mt/desktop/ => Redirects to the destkop url,while maintaining the current path and setting a cookie.
- /mt/mobile/ => redirect to the mobile url, while maintaining the current path and setting a cookie.

It should be a more stable implementation in case in the settings.php file, the $cookie_domain variable is not set.

This brings us to a second requirement (but with the new implementation, not critical) is that you should set the $cookie_domain variable in the settings.php file to:

$cookie_domain = '.domain.com'; // the dot is very important.

This way all the cookies that are set are valid for both the mobile and the desktop url. So there will only be one cookie with domain = .domain.com

Hope this helps!

Hmm. We don't want the cookie_domain set to .mydomain.com since we have subdomains set up to sever static content, and we need this static content to be served without cookies. In order do do that, we need to ensure that cookies are set for .www.mydomain.com and not .mydomain.com. This means that when images are served from static.mydomain.com the don't get requested with cookies since no cookies were ever set for that domain.

hi,
i want to know that from my desktop site mobile theme not show but device detection work properly

A teacher, or the prison, more and more ares are considering the legal use of cell phone jammers, it has been a necessity of our daily life, I have got one from jammerall.com for my family. so if you want to get one, you can go and visit it for more details. share with you!

I can confirm it on 6.x-2.7. Unfortunately renders the whole module unusable.

Even worse, the script goes to loop between the mobile and desktop website until the browser kills the process over too many redirects as appropriate.