473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Popup at mouse X/Y problem

2 New Member
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 2103
wookaru
4 New Member
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 Recognized Expert Top Contributor
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
jbailiss
2 New Member
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.