/    Sign up×
Community /Pin to ProfileBookmark

It’s taking me all day to find a way to put the sizes of the browser window into PHP variables. So it’s something like this:

[code=php]<?php
$width=window.width;
$height=window.height;
?>[/code]

What’s the correct coding for that? And is there a way to refresh these variables onresize? Thanx!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@razvanpatMar 27.2005 — I'm not really sure about this but I think it will work:


[code=php]
<? if(!isset($width)) ?>
<script language="javascript">

if (navigator.appName=="Netscape") {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
location.href="thispage.php?width="+winW+"&height="+winH;

</script>
<? else
// the rest of the page here
[/code]


About refreshing the page on resize.. i don't think it can be done.. maybe someone else knows...
Copy linkTweet thisAlerts:
@the_treeMar 27.2005 — php, being [b]server side[/b] doesn't know anything about the browser, or even if there is one, ergo, it cant be done.
×

Success!

Help @The_Anime_King 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,
)...