Getting window size to php variable without pulling a second page.
I have a search script I wrote in php which parses any url and returns data based on the url and it uses the SHTML and apache forcetype to use only one page. I've rewritten the code to use a fluid page layout. I'm trying to get the the browser window size so if they are on a phone it will pull smaller ads and on a desktop it will display the larger ads.
I have tried a lot of different scripts and got it to work if it pulls a second page while setting a session var but it messes with the parsing... and my eyes are bleeding from reading...
I have this... trying to send back to itself but it's not setting the post vars...
I would like it to process this first and pass the var back while retaining the Request URI without having to call the page again.
Thanks,
Bob <?php
- if(!isset($_POST['width']) || !isset($_POST['height'])) {
- echo '
- <script type="text/javascript" src="jquery.min.js"></script>
- <script type="text/javascript">
- f$(document).ready(function () {
- var height = $(window).height();
- var width = $(window).width();
- $.ajax({
- type: \'POST\',
- url: test2.php,
- data: {
- "height": height,
- "width": width
- },
- success: function (data) {
- $("#viewarea").html(data);
- },
- });
- });
- </script>
- ';
- }
- echo "<h1>Screen Resolution:</h1>";
- ?>
- <?php
- echo "Width : ".$_POST['width']."<br>";
- echo "Height : ".$_POST['height']."<br>";
- ?>