根据屏幕分辨率包含 php 个文件
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");
}
}
?>
我的问题是,当我加载我的页面时,我有一条错误消息显示了半秒钟,上面写着:"undefined variable 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>
首先,抱歉我的英语不好...
我的网页有些问题:
我想根据屏幕分辨率加载不同的样式。
我在我的页面中包含文件 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");
}
}
?>
我的问题是,当我加载我的页面时,我有一条错误消息显示了半秒钟,上面写着:"undefined variable 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>