简体   繁体   English

根据在Javascript中检测到的屏幕分辨率重定向到PHP中的响应站点

[英]Redirecting to responsive site in PHP based on screen resolution detected in Javascript

Currently I have a PHP library that looks at header information and decides what kind of browser/device the user is using to access my site. 目前,我有一个PHP库,用于查看标头信息并确定用户使用哪种浏览器/设备访问我的网站。 I hooked up my router to this library so that when a user is at my site, based on what the PHP library say I redirect him to a mobile or desktop version. 我将路由器连接到该库,以便当用户在我的站点上时,根据PHP库所说的,我将其重定向到移动或台式机版本。 All this happens in pure PHP. 所有这些都发生在纯PHP中。

Now the complication is that many tablet devices have such wide screens that showing them a responsive site for their screen dimension does not really make much sense. 现在的麻烦在于,许多平板电脑设备的屏幕如此宽阔,以至于无法向他们展示其屏幕尺寸的响应位置确实没有多大意义。 I would like it that my router can get information about the screen dimension/viewport of the user and then make the choice instead of just checking if it isTablet() . 我希望路由器可以获取有关用户的屏幕尺寸/视口的信息,然后做出选择,而不只是检查它是否为isTablet()

I know that I need to use Javascript for this. 我知道我需要为此使用Javascript。 I wanted to check if anyone has experience doing something like this. 我想检查是否有人有做过这样的事情的经验。 To keep it clean, I would like my router to be the decision maker, and not have both Javascript and PHP making independent decisions on where to redirect. 为了保持整洁,我希望路由器成为决策者,而不是让Javascript和PHP都对重定向的位置做出独立的决定。 Is there any library/strategy to handle this use case that anyone has prior experience of? 是否有任何图书馆/策略可以处理任何人都有过使用经验的用例?

You can use the windows width to check for a redirect in your <head> , that redirect should set a $_SESSION variable to not show the mobile site in php . 您可以使用Windows宽度检查<head>中的重定向,该重定向应设置$_SESSION变量以不显示php的移动网站。

The following method requires that the jQuery library be loaded in <head></head> and placing: 以下方法要求将jQuery库加载到<head></head>并放置:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

JS: JS:

if ( $(window).width() > 1000 ) {
  document.location = '/no-mobile-redirect.php?set=true';
}

no-mobile-redirect.php would have no-mobile-redirect.php将有

<?php
session_start();
$_SESSION['noMobileRedirect'] = isset($_GET['set']);
header("Location: /home");

暂无
暂无

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

相关问题 javascript已检测到如何将屏幕分辨率数据调整为适用于Web - how to adapt screen resolution data to web once already detected by javascript 根据屏幕分辨率(js)加载php文件 - Load a php file based on screen resolution (js) 如何在javascript和/或php中获得访问者的屏幕分辨率? - How to get screen resolution of visitor in javascript and/or php? 检测到错误的屏幕分辨率-为什么检测到较小的分辨率? - Wrong screen resolution detected - Why is a smaller resolution detected? 根据 javascript 检测到的屏幕宽度修改布局的缺点 - Disadvantages of modifying layout based on screen width as detected by javascript 当检测到一定的最小屏幕分辨率大小时,如何通过Javascript更改CSS属性 - How can I change a CSS attribute by Javascript when a certain minimum screen resolution size is detected 有没有办法在不使用JavaScript的情况下根据屏幕分辨率调整图像大小? - Is there any way to resize the images based on screen resolution with out using javascript? PHP,JavaScript-通过重定向标头检测屏幕宽度是否正确 - PHP, JavaScript - Is it right to detect screen-width by redirecting header 我想制作一个响应式横幅,它会根据分辨率屏幕的 php、js 和 html - I want to make a responsive banner, that changes depending of the resolution screen with php, js and html 网站分辨率修复,适用于Javascript中的所有分辨率 - Web site resolution fix for all resolution in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM