简体   繁体   English

移动网站脚本重定向

[英]Mobile site script redirect

I have a joomla site and i have build a jquery mobile website so i use this this code below, 我有一个joomla网站,并且已经建立了一个jquery移动网站,所以我在下面使用此代码,

<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 但是我的问题是,在我的jquery网站中,我有一个完整的网站视图,此代码已将其放在主模板的index.php中,因此在joomla创建的每个页面中,用户都可以看到此代码

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. 我的问题是,当用户从移动jquery网站“查看完整网站”单击时,如何将其编写,而不是再次将他重定向回移动网站,我该如何编写该脚本。

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.. 因为当用户按下按钮查看完整站点时转到了完整站点,几秒钟后他又回到了移动原因。

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 . 这可以用JavaScriptphp完成

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. 如果要坚持上述客户端方法,则可以在创建setCookie()和之后,将if语句修改为if (screen.width <= 680 && readCookie('screenpref') != 'desktop') {} readCookie()函数。

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/ 就像Joe所说的,我也推荐一种服务器端解决方案,它可以更有效地检查我刚刚发现的链接,这是一个相当全面的用户代理列表,您可以在以下网址上进行重定向: 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. 基本上,它是一个字符串,您可以用来识别哪个设备请求了您的网页。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM