<分区>
我想在加载网页时在 GET 中添加屏幕的宽度和高度,以便我的页面可以使用这些 var 重定向到特定页面。
我找过函数,看来我应该使用 window.screen.width
和 window.screen.height
此外,我发现我应该使用 $.get()
来发送变量。
所以我想出了这个脚本,但我假设我正在混合 JS 和 AJAX,不管是否可行,我都不会这样做。最重要的是,我不知道如何在我的页面加载时运行该功能。
$(document).ready(function() {
ratio();
function ratio() {
var Vorientation;
if(window.screen.width>window.screen.height)
{
Vorientation = 1;
}
else
{
Vorientation = 2;
}
$.get( "index.php?orientation="+Vorientation );
alert("ok");
}
});
这是 html :
<body>
<?php
if(isset($_GET['orientation']))
{
echo"ok";
}
?>
</body>