JS to get the location of the control

From , 5 Years ago, written in JavaScript, viewed 205 times.
URL https://pastebin.vip/view/1fd7b875
  1. //获得控件的位置
  2. function getAbsolutePosition(obj)
  3. {
  4. position = new Object();
  5. position.x = 0;
  6. position.y = 0;
  7. var tempobj = obj;
  8.     while(tempobj!=null && tempobj!=document.body)
  9.     {
  10.         if(window.navigator.userAgent.indexOf("MSIE")!=-1)
  11.         {
  12.             position.x += tempobj.offsetLeft+4;
  13.             position.y += tempobj.offsetTop+5;
  14.         }
  15.         else
  16.   {
  17.    if(window.navigator.userAgent.indexOf("Firefox")!=-1)
  18.          {
  19.             position.x += tempobj.offsetLeft;
  20.             position.y += tempobj.offsetTop;
  21.          } else  {
  22.       position.x += tempobj.offsetLeft+4;
  23.             position.y += tempobj.offsetTop+5;
  24.      }
  25.    }
  26.         tempobj = tempobj.offsetParent
  27.     }
  28. return position;
  29. }

Reply to "JS to get the location of the control"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website