Solved

Window.open (small popup) at current mouse position

Posted on 2003-11-30
4
14,012 Views
Last Modified: 2012-06-22
I'm working on an .net page where I have a few date fields. I've got a button for each field where the user can open up a popup calender page. I would like the new window to open up where the button is pressed.
0
Comment
Question by:toederud
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Christian_Wenz earned 50 total points
Comment Utility
first, detect the mouse position:

var x, y;
window.onload = init;

function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
  x = (window.Event) ? e.pageX : event.clientX;
  y = (window.Event) ? e.pageY : event.clientY;
}


then open the window and move the window to the mouse position:

<input type="button" onclick="openWin()" value="click me" />

function openWin() {
  var w = window.open("page.html", "xy", "options");
  w.moveTo(x, y);
}

0
 

Author Comment

by:toederud
Comment Utility
This works fine in IE and NS but what changes can be made to make it work in Opera?
0
 

Author Comment

by:toederud
Comment Utility
I get an error on the document.captureEvents(Event.MOUSEMOVE); line in Opera.

Since I live in Norway and many off the sites users use Opera it is esential that this works in Opera.
0
 
LVL 5

Expert Comment

by:Christian_Wenz
Comment Utility
Opera uses window.captureEvents(Event.MOUSEMOVE), so you might check for that:

if (window.Event) {
    if (document.captuerEvents){
      document.captureEvents(Event.MOUSEMOVE);
    } else {
      window.captureEvents(Event.MOUSEMOVE);
    }
  }
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now