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)

New User

10+ Year Member

joined:Apr 7, 2007
posts: 20
votes: 0

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)

Senior Member from CA 

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

joined:Aug 29, 2003
votes: 0

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:

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members