[英]Include php file according to screen resolution
首先,对不起我的英语不好...
我的网页有些麻烦:
我想根据屏幕分辨率加载不同的样式。
我在页面中包含文件style.php。
这是代码:
<?php
if(!isset($_GET['screen_check']))
{
echo "<script language='JavaScript'>
<!--
document.location=\"$PHP_SELF?screen_check=done&Width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else
{
if(isset($_GET['Width']) && isset($_GET['Height'])) {
if(($_GET['Height']/$_GET['Width']) < 0.6)
{
include("stylew.php");
}
else {
include("stylen.php");
}
}
else {
include("stylen.php");
}
}
?>
我的问题是,当我加载页面时,显示了半秒钟的错误消息,其中说:“未定义的变量PHP_SELF”,这有点可怕...尽管如此,它仍然有效!
我想做类似的事情:
<script>
if (screen.height / screen.width) < 0.6)
{
<?php include stylew.php ?>
}
else
{
<?php include stylen.php ?>
}
在不重新加载页面的情况下获取我的变量。 我怎样才能做到这一点 ?
先感谢您 !
媒体查询将是最好的。
使用javascript:使用jQuery进行宽度/高度检测的兼容性。
喜欢 ...
<script>
document.addEventListener('DOMContentLoaded', function() {
var newStyle = document.createElement('link');
newStyle.rel = 'stylesheet';
newStyle.type = 'text/css';
if ( ($(window).height() / $(window).width()) < 0.6 ) {
newStyle.href = 'http://xxx1';
} else {
newStyle.href = 'http://xxx2';
}
document.getElementsByTagName('head')[0].appendChild(newStyle);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.