我有一點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