/    Sign up×
Community /Pin to ProfileBookmark

Display resolution and web site version

Hey guys!
I have a problem, and hope you can help me!

Is there any way to determine wich resolution the viewer is using, and depending on it, to load differrent html files? For example if it is 1024 to load index.html, and if it is 1280 to load index2.html?

Thanks a lot!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NyfaelSep 21.2006 — You should make your page dynamic enough to do it on it's own.. you can use styles, etc. etc., but if you really want to, there is a way.

PHP is serverside, meaning it does stuff on the server. If I'm correct, the only way to get the resolution is to use javascript:

window.screen.width

window.screen.height

But since you can't dynamically include a page based on javascript, you would have to make it go to one page, grab the variables, load another page, and then that page could dynamically include a file.

As I said, just making your website support multiple widths is better.

And if you don't know how to grab php variables, one way is to put php on the page looking for a form request. If it's not there, then it sticks in the javascript code in a form value, and submits the form to itself. The page then reloads, the php sees that the form has submitted, and now you have the screen width and height in php, and can do whatever you want.

A sort of reverse AJAX could be useful, though I have no idea how to do that.

-Kerry
Copy linkTweet thisAlerts:
@felgallSep 21.2006 — The available space in the browser is less than the screen resolution (much less if the browser is not open full screen). About the only things you can rely on are that people using web readers don't have a resolution, those using webTV have a fixed width of 544 pixels, those using handheld devices are unlikely to have resolutions above 300 pixels, and those using large screen resolutions are less likely to open their browser full screen.
Copy linkTweet thisAlerts:
@NyfaelSep 22.2006 — Read this:

http://www.javascripter.net/faq/browserw.htm

That can get you the width of what you need. I did a bit more research, as I got off on programming tangent.

If you want to get it dynamically, put it in another .htm page as javascript that spits out the right variables.

This will allow you to use php file_get_contents and get the appropriate data. You can use the explode() function to parse it out however you want.

Sincerely,

Kerry
×

Success!

Help @byte_eater 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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