Get the window width and height in JavaScript using a cross-browser function that works with all versions of Internet Explorer and Firefox.
-
function GetWidth()
-
{
-
var x = 0;
-
if (self.innerHeight)
-
{
-
x = self.innerWidth;
-
}
-
else if (document.documentElement && document.documentElement.clientHeight)
-
{
-
x = document.documentElement.clientWidth;
-
}
-
else if (document.body)
-
{
-
x = document.body.clientWidth;
-
}
-
return x;
-
}
-
-
function GetHeight()
-
{
-
var y = 0;
-
if (self.innerHeight)
-
{
-
y = self.innerHeight;
-
}
-
else if (document.documentElement && document.documentElement.clientHeight)
-
{
-
y = document.documentElement.clientHeight;
-
}
-
else if (document.body)
-
{
-
y = document.body.clientHeight;
-
}
-
return y;
-
}
浙公网安备 33010602011771号