I would like, when i'm loading a webpage, to add in GET the width and height of the screen, so that my page can use these var to redirect to a specific page.
I've looked for the function and it seems that I should use window.screen.width
and window.screen.height
Also, I figured out I should use $.get()
to send the variables.
So I came out with this script, but i assume i'm mixing JS and AJAX which I don't if it's ok or not. And most of all, I don't know how to run the function when my page is loading.
$(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");
}
});
Here is the html :
<body>
<?php
if(isset($_GET['orientation']))
{
echo"ok";
}
?>
</body>
mixing js and ajax
: AJAX is not a language, it's a way of retrieving a response from a server (e.g. from PHP code) with javascript, often used to generate content on the page based on user input.$.get
is jQuery (which is a js lib) to perform a ajaxGET
requestvar Vorientation;