/    Sign up×
Community /Pin to ProfileBookmark

window width and height

I am trying to determine what the users window width and height are when they open it. I would like my background image to adjust in size. I have tryied to use innerHeight and height. Does anyone have a good idea how to go about this?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceFeb 15.2006 — This requires cross-browser scripting. Try this out as an example (hint: after displaying this in your browser, resize the window to see the displayed size change).
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Window Resize</title>
<script type="text/javascript">
<!--//
window.onresize = function() {
var str;
if (window.Event) {
str = window.innerWidth + " x " + window.innerHeight;
} else {
str = document.documentElement.offsetWidth + " x " + document.documentElement.offsetHeight;
}
document.getElementById("output").innerHTML = str;
return true;
}
//-->
</script>
</head>

<body>

<p id="output">&nbsp;</p>

</body>
</html>
[/code]
×

Success!

Help @Cowgirl32 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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