Compatible with BackCompat and CSS1Compat pages rendered in two modes. Tested Browser: friefoxie678chromeopera
The Code is as follows:
(Function ($ ){
/**
* Get the width of the browser View
*/
$. ViewWidth = function (){
Var w = 0, D = document;
If (D.doc umentElement & D.doc umentElement. clientWidth ){
W = D.doc umentElement. clientWidth;
} Else if (D. body & D. body. clientWidth ){
W = D. body. clientWidth;
}
Return w;
}
/**
* Get the height of the browser View
*/
$. ViewHeight = function (){
Var h = 0, D = document;
If (document. compatMode! = 'Css1compat '){
H = D. body. clientHeight;
} Else {
If (D.doc umentElement & D.doc umentElement. clientHeight ){
H = D.doc umentElement. clientHeight;
} Else if (D. body & D. body. clientHeight ){
H = D. body. clientHeight;
}
}
Return h;
}
/**
* Obtain the height of the canvas (that is, the browser view size when the browser content is insufficient)
*/
$. CanvasHeight = function (){
Var D = document, h = 0;
Hsf-math.max(math.max(d.body.scrollheight,d.doc umentElement. scrollHeight ),
Math.max(D.body.offsetHeight,D.doc umentElement. offsetHeight ),
Math.max(D.body.clientHeight,D.doc umentElement. clientHeight)
);
If ($. browser. msie & $. browser. version> 6 & D. body. scrollHeight <$. viewHeight ()){
H = D. body. clientHeight;
}
If ($. browser. msie & document. compatMode = 'css1compat' & D. body. scrollHeight <$. viewHeight ()){
If ($. browser. version> 7 & $. browser. version <9 ){
} Else if ($. browser. version> 6 & $. browser. version <8 ){
}
Hsf-d.doc umentElement. clientHeight;
}
Return h;
}
/**
* Obtain the width of the canvas (that is, the browser view size when the browser content is insufficient)
*/
$. CanvasWidth = function (){
Var D = document, w = D. body. scrollWidth;
If (document. compatMode = 'css1compat '){
W=D.doc umentElement. scrollWidth;
} Else {
If ($. browser. msie & $. browser. version <= 6 & D. body. scrollWidth> $. viewWidth ()){
W=Math.max(Math.max(D.body.scrollWidth,D.doc umentElement. scrollWidth ),
Math.max(D.body.offsetWidth,D.doc umentElement. offsetWidth ),
Math.max(D.body.clientWidth,D.doc umentElement. clientWidth)
);
}
}
Return w;
}
/**
* Obtain the width of the canvas (that is, the browser view size when the browser content is insufficient)
*/
$. ScrollLeft = function (){
If (document. compatMode! = 'Css1compat' | ($. browser. msie & $. browser. version <= 6 )){
Return math.max((('body').scrollleft(,,document.doc umentElement. scrollLeft );
} Else {
Return $ ('body'). scrollLeft ();
}
}
/**
* Obtain the width of the canvas (that is, the browser view size when the browser content is insufficient)
*/
$. ScrollTop = function (){
If (document. compatMode! = 'Css1compat' | ($. browser. msie & $. browser. version <= 6 )){
Return Math. max ($ ('body'). scrollTop (), document.doc umentElement. scrollTop );
} Else {
Return $ ('body'). scrollTop ();
}
}
}) (JQuery );