Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi everyone,

I've stumbled across a problem where on page load, I'm trying to get the browser height and width and put it in the address bar like so:

index.php?height=333width=333

Basically I've managed to get the height and width of the browser window using Javascript, and stored them as:
JavaScript
var myHeight
var myWidth

But I need to use those variables in PHP for many other things. My thought was to put the Javascript variables into the URL bar, where PHP can extract them using SUBSTRING.

Is this possible or is there a different/easier way?

Regards,
Tom.
Posted
Comments
Dasaradhi_r 4-Sep-12 12:23pm    
Is this what you are trying to achieve? Just verify the below link:
http://stackoverflow.com/questions/2260455/a-way-to-determine-browser-width-in-php-without-javascript

1 solution

Lots of website do that already. in the first load send some script that would calculate with window height and width. then create a location redirection here is an example:
C++
<script>
var width=get_window_width();//build the function 
var height=get_window_height();//build the function 
document.location='somelocation_or_samelocation.php?width='+width+'&Height='+height;
</script>
 
Share this answer
 
v2
Comments
Arunprasath Natarajan 4-Sep-12 23:32pm    
Friend.. Will it works in all the browser?
Mohibur Rashid 5-Sep-12 1:17am    
if you use this code without proper changes it wont work on any browser.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900