Title: Jquery Help needed &#8230;.
Last modified: August 20, 2016

---

# Jquery Help needed ….

 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/jquery-help-needed/)
 * Hi,
    I am not that good with JQuery so I am looking for a little help with this
   solution for an ad banner, this is for a free theme not a commercial venture!
 * I want to return the screen width with jquery back to a php variable when the
   page loads.
 * What I want to do is with a twenty eleven child theme, the theme is responsive
   but Google ads are not, it looks silly on a mobile if the banner is wider than
   the screen.
 * So only once when WordPress opens in a browser if we can get the screen width
   stored in a variable, then we can load a different adSense banner block based
   on the screen width.
 * If the page is opened in a mobile we can display a mobile sized banner.
 * I have been on google without much luck.
 * If we have a function something like this, how can we get the returned screen
   width from a JQuery call to a php variable?
 * This does not work!
 *     ```
       $dr_screen_width = 0;
       ```
   
 *     ```
       <script type="text/javascript">
       (function($){
       	$(document).ready(function () {
       		var $dr_screen_width;
       		$dr_screen_width = $(window).width();
       	});
       })(jQuery);
       </script>
       ```
   
 * Any help most welcomed.
 * Hopefully
 * David

Viewing 1 replies (of 1 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/jquery-help-needed/#post-2802025)
 * You can’t send a value from jQuery to PHP, not directly. By the time the Javascript(
   jQuery) runs the PHP has long since finished and has moved on to other things.
   You are going to have to take an Ajax like approach. That is, let the page load,
   then run the jQuery which gets, or tries to get, the screen width and replaces
   the banner block with a more appropriate one.
 * You could also try something like this: [http://mobiforge.com/developing/story/lightweight-device-detection-php](http://mobiforge.com/developing/story/lightweight-device-detection-php)
 * Some devices lie though. Mine does. I hate mobile sites. I want the normal one.
   🙂

Viewing 1 replies (of 1 total)

The topic ‘Jquery Help needed ….’ is closed to new replies.

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [screen width](https://wordpress.org/support/topic-tag/screen-width/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/jquery-help-needed/#post-2802025)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
