dbz
dbz

Reputation: 284

Mobile site script redirect

I have a joomla site and i have build a jquery mobile website so i use this this code below,

<script type="text/javascript">
<!--
if (screen.width <= 680) {
window.location = "site.com";
}
//-->
</script>

But the my problem is that in my jquery site i have a view full site this code i have put it in index.php of my main template so in every page that joomla creates so user can see this code exist

My question is how i can write this script when the user click from mobile jquery site "view full site" and not again redirect him back to mobile site.

Because when the user press the button view full site went to the full site and after seconds he turn back to mobile cause of this script..

Upvotes: 0

Views: 672

Answers (2)

John
John

Reputation: 3546

Like Joe said I also reccomend a serverside solution which is way more efficient check this link I just found, which is a quite comprehensive list of user agents you can check to redirect on : http://detectmobilebrowsers.com/

For those of you that don't know the user agent is part of the header of the request and describes the client software that oriniganated the request. Basicly its a string that you can use to identify which device requested your web page.

Upvotes: 0

Joe Cape
Joe Cape

Reputation: 403

Ideally, the switch should be done server-side, as the overhead in sending the page to the browser only to be redirected is unnecessary.

Here is a link to get you started with that but to focus on a your specific question: You can store the preference in a session variable which is then checked in your conditional above. This can be done either in JavaScript or php.

If you were to stick to your client-side approach above, you could modify the if statement to if (screen.width <= 680 && readCookie('screenpref') != 'desktop') {} after creating your setCookie() and readCookie() functions.

Upvotes: 1

Related Questions