Jump to content

Get browser width?


sciencebear

Recommended Posts

Are you going to send the width off to php through a form or an ajax request? Because you can't detect the page width before it is loaded.

 

To assume you are doing the latter, you can use the jQuery library to do a single, cross browser read, as outlined here:

 

http://api.jquery.com/width/

 

Like so:

 


$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document

Link to comment
https://forums.phpfreaks.com/topic/199135-get-browser-width/#findComment-1045178
Share on other sites

Hi again. I was able make a function GetWidth() that returns the variable I need. I can make it show in html by using this code:

 

<script type="text/javascript">document.write(GetWidth())</script>

 

However, I need to use that value in PHP. How can I define that as a PHP variable?

 

Edit: I am only using it to define the width of a div tag (It's not just 100%, GetWidth performs some other operations to the browser width). If there's an easier way to do this without PHP, I could do that as well.

Link to comment
https://forums.phpfreaks.com/topic/199135-get-browser-width/#findComment-1045754
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.