473,288 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Popup at mouse X/Y problem

Hi, I've been playing around with trying to get a popup window to open following a mouse click at the position of the mouse.

The following (hastily put together) code works in IE but Firefox is unresponsive.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <head>
  3. <script language="JavaScript"><!--
  4. function showWindow(e) {
  5.     posx=0;posy=0;
  6.     var ev=(!e)?window.event:e;//IE:Moz
  7.     if (ev.pageX){//Moz
  8.     posx=ev.pageX+window.pageXOffset;
  9.     posy=ev.pageY+window.pageYOffset;
  10.     }
  11.     else if(ev.clientX){//IE
  12.     posx=ev.clientX+document.body.scrollLeft;
  13.     posy=ev.clientY+document.body.scrollTop;
  14.     }
  15.     else{return false}//old browsers
  16.     myWindow=window.open('coordinates.html','windowName','width=100,height=100,screenX=' + posx + ',screenY=' + posy + ',left=' + posx + ',top=' + posy);
  17. }
  18. //--></script>
  19. </head>
  20. <body>
  21. ..............................<a href="#" onClick="showWindow();">hxgdfh</a>
  22. </body>
  23. </html>
BUT... adding in a "document.onclick=showWindow" sees the code working in both browsers (but, obviously, from any click in the window - rather than just the link text)

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <head>
  3. <script language="JavaScript"><!--
  4. function showWindow(e) {
  5.     posx=0;posy=0;
  6.     var ev=(!e)?window.event:e;//IE:Moz
  7.     if (ev.pageX){//Moz
  8.     posx=ev.pageX+window.pageXOffset;
  9.     posy=ev.pageY+window.pageYOffset;
  10.     }
  11.     else if(ev.clientX){//IE
  12.     posx=ev.clientX+document.body.scrollLeft;
  13.     posy=ev.clientY+document.body.scrollTop;
  14.     }
  15.     else{return false}//old browsers
  16.     myWindow=window.open('coordinates.html','windowName','width=100,height=100,screenX=' + posx + ',screenY=' + posy + ',left=' + posx + ',top=' + posy);
  17. }
  18. document.onclick=showWindow
  19. //--></script>
  20. </head>
  21. <body>
  22. ..............................<a href="#" onClick="showWindow();">hxgdfh</a>
  23. </body>
  24. </html>
Any ideas on making the code work without the "document.onclick=showWindow" would be very helpful.

Thanks!
Feb 27 '07 #1
3 2096
I have had success using:

posx=ev.clientX+pageXOffset;
posy=ev.clientY+pageYOffset;

for the position in Firefox. Hope that helps
Feb 27 '07 #2
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <head>
  3. <script language="JavaScript"><!--
  4. var posx;var posy;
  5. function getMouse(e){
  6. posx=0;posy=0;
  7. var ev=(!e)?window.event:e;//IE:Moz
  8. if (ev.pageX){//Moz
  9. posx=ev.pageX+window.pageXOffset;
  10. posy=ev.pageY+window.pageYOffset;
  11. }
  12. else if(ev.clientX){//IE
  13. posx=ev.clientX+document.body.scrollLeft;
  14. posy=ev.clientY+document.body.scrollTop;
  15. }
  16. else{return false}//old browsers
  17. }
  18. document.onmousemove=getMouse
  19. function showWindow(e) {
  20.  myWindow=window.open('coordinates.html','windowName','width=100,height=100,screenX=' + posx + ',screenY=' + posy + ',left=' + posx + ',top=' + posy);
  21. }
  22. //--></script>
  23. </head>
  24. <body>
  25. <a href="javascript: void(0);" onClick="showWindow();">hxgdfh</a>
  26. </body>
  27. </html>
  28.  
try this out
Feb 27 '07 #3
Thanks guys - I've sort of answered my own question though.

It seems I was being very sloppy (being a bit of a JS newb) and the link should have been <a href="#" onClick="showWindow(event);">

Thanks for the code though iam_clint, it's definitely a good option!
Feb 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Greg Bacon | last post by:
We have a messaging application that makes seemingly unremarkable use of a HelpProvider component. However, after we've received a message, if we display the help popup (either via F1 or through...
1
by: MJEASSOC | last post by:
I need some help with closing a popup window. I'm making an online portfolio, that has one base page with text and thumbnails. When a user clicks on a thumb, a new window opens containing a larger...
3
by: Roger Withnell | last post by:
My simple popup menu code works in IE (Windows and Mac) but not in Safari. I use a onmouseover ShowMenu function and a onmouseout HideMenu function. Because Safari, unlike IE, recognises...
17
by: Applebrownbetty | last post by:
Hi, I'd like to append/amend the following code from the Dreamweaver extension "Open Picture Window Fever" for the ability to center the PopUp window: By default, it allows the window to be...
24
by: jonathon | last post by:
Hi all, I have a web app with a popup window for entering data. I don't want to access the web every time this window is opened, as most of the app is AJAX. But I can't figure out how to open...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
3
by: atn2002 | last post by:
I'm trying to create a control which when the mouse button gets pressed on one div an absolute positioned div pops up in place of the cursor. From there the cursor should interact with the dialog...
4
by: jobs | last post by:
the javascript: function ShowTooltip(L1in) { document.getElementById("L1").innerText=L1in; y = event.clientY + document.documentElement.scrollTop; var Popup= document.getElementById("Popup")...
1
by: johnix | last post by:
i am a bigenner in this field of web programming.. i like to create a dynamic dropdown menu that the data should came from the database but i dont know how to do it. what i did is I use the table and...
1
by: dheepakk | last post by:
Hi All, When a mouseover event takes place over a link the popup window is displayed. I also have a mouseout on the link.So if the popup window comes up,has a dimension such that the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.