javascript - Conundrum - need to get viewport size in PHP (or any other way around it) -


basically, have site that's written in javascript, i've decided rewrite in php. main bit i'm replacing uses spry read values off xml dataset javascript variables.

php mysql can take on jobs i'm using spry for, there's 1 other part of script i'd make server-side.

what goes on page loads, function decides size picture should be, , therefore size on server. there 5 files of different sizes, , chooses smallest 1 doesn't have upscale (but can downscale). combines information spry, , sets src of img element, not set (this part of hate current setup).

i've done googling, , know problem - php parses server-side, @ point can't know screen size.

i can without - either keep existing javascript task, bit unstable, or use 1 size of image, make site not good.

i'm wondering if expert has trick sleeves having php decide image embed. i'm guessing there's nothing browser sends when first requests site.. woulda showed in googling..

i should mention, i've not done php apart simple thing there's tab bar on pages of site, , use php bring in , change appearance of selected tab.

you have few options:

option 1: output simple page js gets browser specs , redirect, passing specs along query args. e.g.

http://example.com/stage2.php?x=1024&y=768

this stage2 script can build real page based on passed-along specs.

option 2: use ajax lazy loading. primary content of page gets specs, passes them via ajax call, , response rest of html, adjusted reflect specs. e.g

$('#body').load('example.com?x = ' + window.width + ......); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -