inherit
58740
0
Aug 20, 2024 7:29:21 GMT -8
®i©hie
I'm not very active here anymore thanks to my full-time job. - 12/27/23
14,036
September 2005
soe
|
Post by ®i©hie on Nov 4, 2009 16:34:32 GMT -8
What's the IF statement to check the Width of the screen?
i can't seem to find it, & i've searched google already.
|
|
inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Nov 4, 2009 17:13:20 GMT -8
I think it is
if(screen.width == "width")
|
|
inherit
58740
0
Aug 20, 2024 7:29:21 GMT -8
®i©hie
I'm not very active here anymore thanks to my full-time job. - 12/27/23
14,036
September 2005
soe
|
Post by ®i©hie on Nov 4, 2009 17:36:42 GMT -8
I think it is if(screen.width == "width") that was close but actually i figured it out, thanks though ;D
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 4, 2009 18:23:29 GMT -8
What is it, exactly?
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 4, 2009 18:48:28 GMT -8
Depends on the browser. I posted a cross-browser method before, that was long and complicated and shiz.
Copy-pasted from the old thread (http://support.proboards.com/index.cgi?board=programming&action=display&thread=283516):
Editted to be sexier:<script type="text/javascript"><!--
var cb = function() { var value = false, a, child, parent, isObject; for (a = 0; a < arguments.length - 1; a++) { isObject = (typeof(arguments[a]) == "object" ? true : false); child = (isObject ? arguments[a][0] + '.' + arguments[a][1] : arguments[a]); parent = (isObject ? arguments[a][0] : false); eval("if (" + (parent ? "typeof(" + parent + ") != \"undefined\" &&" : "") + "typeof(" + child + ") == \"number\" && " + child + " > 0" + (value ? " && " + child + " < " + value : "") + ") { value = " + child + "; }"); } return (value ? value : arguments[arguments.length - 1]); }
var height = cb("window.innerHeight", ["document.documentElement", "clientHeight"], ["document.body", "clientHeight"], 0), scrollLeft = cb("window.pageXOffset", ["document.documentElement", "scrollLeft"], ["document.body", "scrollLeft"], 0), scrollTop = cb("window.pageYOffset", ["document.documentElement", "scrollTop"], ["document.body", "scrollTop"], 0), width = cb("window.innerWidth", ["document.documentElement", "clientWidth"], ["document.body", "clientWidth"], 0);
alert(width + "x" + height);
--></script>
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 4, 2009 19:54:16 GMT -8
... That's much bigger than I thought.. and you would use that with an if(statement) .. how?
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 4, 2009 21:55:43 GMT -8
He put some examples above including how to call the function to return the width of the page.
var width = cb("window.innerWidth", ["document.documentElement", "clientWidth"], ["document.body", "clientWidth"], 0);
So the if statement would be:
if(width == SomeInteger)
Or if you want to call the function directly and not store the value in a variable for later use:
if(cb("window.innerWidth", ["document.documentElement", "clientWidth"], ["document.body", "clientWidth"], 0) == SomeInteger)
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 5, 2009 10:42:13 GMT -8
Yeah, it's not all that long. I just included width, height, scrollLeft, and scrollTop. If you don't need those defined, then you can remove what you don't need.
For example, if you're only using width, then:
var width = cb("window.innerWidth", ["document.documentElement", "clientWidth"], ["document.body", "clientWidth"], 0);
if (width < 800) alert("Your screen isn't big enough!");
|
|