我有一点JS代码(由PHP回声),将放在我的网页的顶部。代码应该评估窗口大小,并基于此,转到移动版本或转到PC版本。js window.redirect不断更新
但是,当我loead我的网页(PC版),页面不断刷新。我怎样才能令人耳目一新?
下面的代码:
$page = $_SERVER["PHP_SELF"];
echo "<script>";
echo "function screenSizeRedirect()
{
var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
if (width <= 960)
{
window.location = 'http://m.bss21universe.ga$page';
}
if (width > 960)
{
window.location = 'http://www.bss21universe.ga$page';
}
}";
echo "screenSizeRedirect();";
echo "</script>";
你能提供围绕片段的上下文吗?在页面中特别是在什么点加载? – Romuloux