One of the frequent problems is defining visitor’s screen resolution using JavaScript tools and passing this data to PHP-script. The following script provides solution for this problem:
width = screen.width;
height = screen.height;
if (width > 0 && height >0) {
window.location.href = "http://localhost/main.php?width=" + width + "&height=" + height;
} else
exit();
Copy and paste this code snippet in the text editor, save it as index.htm and run it in your browser. After this code has been executed, a user is automatically redirected to the main.php page where screen resolution is displayed in the browser window.
The main.php looks as follows:
echo "
Screen Resolution:
";echo "Width : ".$_GET['width']."
";
echo "Height : ".$_GET['height']."
";
?>
No comments:
Post a Comment