July 19, 201214 yr Hey all, I've been trying to figure this piece of code out for the last couple of hours, coding is not my strong point I have to say! Basically, I want to work out the size of the users screen resolution (for which I've found a few of Javascripts to print the result), but then I want to output it into the code of a page, as below: $imgDimensions = array( 'height' => 'RESULT_HERE' ); I've tried echos, prints, functions as well as trying to get the whole script in there itself! Any ideas how this might be done? The site is on Wordpress if that helps. Thanks Tom Edited July 19, 201214 yr by blackwebs
July 19, 201214 yr Not very easily. PHP is server-side, Javascript is client-side. All the PHP on your page will have been processed long before it gets to the stage of loading any JS. As it Wordpress, your best bet would probably be to use a jQuery AJAX post to send the dimensions as a variable to a PHP page.
July 19, 201214 yr Author Hi, I'm seeing that you're right about the AJAX requirements from the reseach I've been doing - totally lost now though! I'm trying to get an images height to match that of the users broswer window... Thanks Tom
July 19, 201214 yr Could you not do that using CSS? Or are we talking actually serving different images depending on the window size? Because...I don't think you'll be able to do that. Responsive images is a very contentious issue at the moment. But if you're okay serving one image, just use your normal CSS.
July 19, 201214 yr Author I'm already using a responsive image plugin - but not for this, it's not quite the same. Basically I have a horizontal scrollbar area which can be set to any height manually which makes the images inside it larger and in proportion. So what I'm looking to do is, find out the height of the user's window and parse that result into the code. This is the code (the height is set manually in the WP admin area): $imgDimensions = array( 'height' => get_option_max( 'image_fullsize_scroller_height' ) ); If I manually edit it this to: $imgDimensions = array( 'height' => ‘650’ ) ); It will make everything 650px height and keep proportion, which is what I want. So this is where I want to parse the code into. Headache! Edited July 19, 201214 yr by blackwebs
July 20, 201214 yr I'm confused. You are setting inline dimensions for the image, right? i.e. width="350" etc. Well, just over ride with CSS? I don't really get the problem, if you want images to change size depending on the browser size, then use percentage widths. Your PHP code is or should be fairly irrelevant.
Create an account or sign in to comment