/    Sign up×
Community /Pin to ProfileBookmark

Using JavaScript’s Screen Resolution

I have a question. First, am I correct in assuming that PHP cannot return the screen resolution of a user?

Next, I know that JavaScript can, but can I use JavaScript to determine the resolution and then use php to change the output of the page?

For example, I want to change the Picture header of my page based on Screen Resolution. Please help me out. Thanks……….Lan

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@LanauthorFeb 23.2005 — Nevermind. It looks like I've found I cannot do JavaScript -> PHP comunication anyway. I think I'm going to have to get my hands dirty learning js. Thank you anyway............Lan
Copy linkTweet thisAlerts:
@bokehFeb 23.2005 — The problem doing things client side is you never know what they have switched on and what they have switched off. (When I loaded SP2 Javascript was disabled by default).
Copy linkTweet thisAlerts:
@phpnoviceFeb 24.2005 — [i]Originally posted by Lan [/i]

[B]I have a question. First, am I correct in assuming that PHP cannot return the screen resolution of a user?[/B][/QUOTE]

That is correct.
[i]Originally posted by Lan [/i]

[B]Next, I know that JavaScript can, but can I use JavaScript to determine the resolution and then use php to change the output of the page?[/B][/QUOTE]

Yes, you can use JavaScript to communicate with PHP -- provided, of course, that JavaScript isn't disabled. Depending upon how you want this communication to work, there are different ways your PHP can get JavaScript to send back such information. Here are the basics:
<i>
</i>self.location.href='mypage.php?w='+screen.width+'&amp;h='+screen.height;
Copy linkTweet thisAlerts:
@LanauthorFeb 25.2005 — phpnovice, thank you very much. I assume you mean passing that through a URL?

And please forgive my ignorance, but do you mind telling me what the self.location.href is, or perhaps explain it a little more.

I see the tie passing 'w' and 'h' to mypage.php, but I don't understand the beginning.

Thank you again for your help.........Lan
Copy linkTweet thisAlerts:
@phpnoviceFeb 26.2005 — That is how JavaScript uses the DOM to perform a redirect. [b]self[/b] is a window-type object reference for the current document's containing window -- which, depending upon whether frames are in use, may or may not be the same as the [b]top[/b] window reference (which is the browser window itself).
Copy linkTweet thisAlerts:
@phpnoviceFeb 26.2005 — [i]Originally posted by bokeh [/i]

[B](When I loaded SP2 Javascript was disabled by default). [/B][/QUOTE]

Mine wasn't.
×

Success!

Help @Lan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...