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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.