This is the JS
to detect the screen resolution on my page naming index.html
and sending it to php, so that the values can be retrived using $_GET
:-
<script type=text/javascript>
width = screen.availwidth;
height = screen.availheight;
if (width > 0 && height >0) {
window.location.href = http://localhost/main.php?width= + width + &height= + height;
} else
exit();
</script>
This is the content of my PHP file naming process.php
:-
<?php
$screen_width = $_GET['width'];
$screen_height = $_GET['height'];
//EDITED PORTION
echo '<style>#Wrapper {width:'.$screen_width.';}</style>';
?>
Now after getting the screen size i want to display the index.php
.
NOTE THESE STEPS, AS TO UNDERSTAND THE WAY I WANT THINGS TO WORK:-
- Page Load Started
- Javascript detected available screen width.
- It passes it to php file and the PHP variable got the screen available screen width.
- Then page get displayed using that php variable (Means the page width is being set using that php variable)
In the whole process the index.php
should not be reloaded. So, How it can be done?
EDIT:
As the JS
passes the value to the php file it gets loaded, what i want is to get the screen resolution and accordingly set the website page width. But if JS
send the data to php file and if at all we get it through ajax, it may can happen that my website get fully loaded and the style would not be implemented because it has already been loaded all the stuffs before the ajax work.
Is there any method which is efficient enough or we can do this one in a way that it become efficient.
This is my EDIT:2
To be more clear i'll actually explain what i want to achieve using the following image:-
Now if ill get the screen resolution say 800px
then i know that i want to deduct 200px
of left side from it, so it will become 600px
and as my divs
are 250px
i'll be able to add only two. Therefore, to avoid showing that 100px
in right i'll adjust my website page width to 700px
.
Things i can do in php, but how to get all things get done at same time on same page?
The whole area you can call as #Wrapper
Right One as #SideBar
Left Area as #LeftContent
Hope i have explained things well. So please if someone can help me doing the needful :)