Click here to Skip to main content
14,694,530 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have to display a popup window using Div tag on a word mousehover, so i tried 2 different Javascript method to dynamically calculate the position of popup window, but non of them working properly, please help me to find the solution:
My method :
function findPosss(obj)
        {
         var obj2 = obj;
         var curtop = 0;
         var curleft = 0;
         if (document.getElementById || document.all) {
          do  {
           curleft += obj.offsetLeft-obj.scrollLeft;
           curtop += obj.offsetTop-obj.scrollTop;
           obj = obj.offsetParent;
           obj2 = obj2.parentNode;
           while (obj2!=obj) {
            curleft -= obj2.scrollLeft;
            curtop -= obj2.scrollTop;
            obj2 = obj2.parentNode;
           }
          } while (obj.offsetParent)
         } else if (document.layers) {
          curtop += obj.y;
          curleft += obj.x;
         }
         return [curleft,curtop];
        }   // end of findPos()

          function getOffset( el )
          {
            var _x = 0;
            var _y = 0;
            while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
                _x += el.offsetLeft - el.scrollLeft;
                _y += el.offsetTop - el.scrollTop;
                el = el.offsetParent;
            }
            return [_x,_y];//{ top: _y, left: _x }
        }


Note: Indirectly you can say i want to dssplay tooltip in IE browser using Javascript.

Any help is appreciated.

Thanks
AP
Posted
Updated 10-Jan-13 1:44am
v4
Comments
ZurdoDev 7-Jan-13 8:43am
   
Have you stepped through the code and debugged it? Is it close? What exactly is wrong with it?
Member 4531085 10-Jan-13 6:00am
   
Actually the popup position is not properly define (let say if a word is top right and when you try to mouse hover the popup come to extreme right and thus it is hidden to users . displyed almost out of screen , actaully it should come to left side of word so that it properly displayed)
   
Popup window is evil in general, and in response to mouseover anything — even worse. Why torturing your user?
—SA
[no name] 10-Jan-13 1:15am
   
i think you have to be think relevant!!!

function popupwindow(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
   
Comments
fjdiewornncalwe 10-Jan-13 9:35am
   
If you are going to copy/paste an answer from somewhere else, you need to provide a link to the original so that you are not flagged abusive for plagiarism. In this case the source is here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900