Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Detect screen resolution and pass it to PHP using AJAX (no refresh)

How to find user's screen resolution and pass it to PHP using AJAX



9:11 pm on Sep 29, 2011 (gmt 0)

5+ Year Member

I'm trying to find the user screen resolution via Javascript and then pass it to PHP on the same page using AJAX without refreshing the page.

I manage to find the screen resolution , but i have no idea how to use AJAX in order to pass the variables to PHP without refreshing the page.

I search the forum and didn't find a got example, please help.

I have:
<script language="javascript">
var viewportwidth;
var viewportheight;
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight

Now i need help to use viewportwidth and viewportheight as PHP variables.



4:51 pm on Oct 3, 2011 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

You won't be able to use these client-side variables in the *same PHP script* that rendered the current page. The best you can achieve is to send the screen data to the server, then the server can use it the *next* time it renders something.

There are lots of nifty tricks you can do, making a second request to the server, to get content that is formatted for a particular screen size, and using DOM techniques to update the current page. It's all possible without a refresh.

i have no idea how to use AJAX

then you've got some reading to do!

start here:

Featured Threads

Hot Threads This Week

Hot Threads This Month