Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 7-Jan-13 1:03am
Edited 10-Jan-13 1:44am
v4
Comments
ryanb31 at 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 at 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)
Sergey Alexandrovich Kryukov at 7-Jan-13 22:20pm
   
Popup window is evil in general, and in response to mouseover anything — even worse. Why torturing your user?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
}
  Permalink  
Comments
Marcus Kramer at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 398
1 DamithSL 235
2 OriginalGriff 230
3 Zoltán Zörgő 149
4 Dave Kreskowiak 120
0 OriginalGriff 7,575
1 DamithSL 5,529
2 Sergey Alexandrovich Kryukov 5,279
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100