SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Location
    Dartford, United Kingdom
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return the screen width to a php variable

    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 WordPress 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!

    This would be set in a php file, I need to get the screen width back from a JQuery function, if this can be done.
    Code:
    $dr_screen_width = 0;
    In a php file, or could go in a *.js file.
    Code:
    <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

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,714
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by David Cox View Post
    If we have a function something like this, how can we get the returned screen width from a JQuery call to a php variable?
    The only is for the jQuery code to submit the information back to the page, which results in the page being called twice.
    This can be done as a form submit, or you could set a cookie value and check to see if that cookie information exists.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •