Saturday, March 31, 2012

How to get page width & height (cross-browsers) with javascript

I spent many hours trying & searching for a stable function working fine across the different browsers and at last i found this code which i can say it's amazing code, type of my favorite way in writing down coding (simple & effective).
This function worked fine and tested on

  • IE 6, 8, 9
  • Opera 11.62
  • FF 11.0
  • Chrome 19.0.1084.1 dev-m
  • Safari 5.1.5
  • Comodo Dragon 18.0
  • Avant browser ultimate 2012 build 28

function GetPageXY() {

var PositionXY = { Width: 0, Height: 0 };
var db = document.body;
var dde = document.documentElement;
PositionXY.Width = Math.max(db.scrollTop, dde.scrollTop, db.offsetWidth, dde.offsetWidth, db.clientWidth, dde.clientWidth);

PositionXY.Height = Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight);

return PositionXY;
}

Reference:
Get document height (cross-browser)    James Padolsey

3 comments:

Anonymous said...

Thаnk you, I have recently bеen searсhing foг
information apprоximately this subjеct for
a lοng time аnd youгs is the best I have cаme upon so far.
However, what about the bottom line? Arе yоu sure in regаrds to the source?


My ρage 1
my web page: Skip Navigation

Anonymous said...

Your own ρoѕt has сonfirmed benеfiсial to
me. It’ѕ really usеful and you're simply certainly very experienced of this type. You have got exposed our eye in order to various views on this specific subject matter using interesting and solid content.

Visit my web page ... buy Xenical
My weblog ... buy Xenical

Anonymous said...

Appreciаtiοn to my fаther who shared ωith me аbout this wеb sіte, this blog iѕ truly aweѕоme.


Looκ at my web ѕite: lawsuit advance ()