Firefox / Javascript question... how do I get the mouse X/Y position across frames?
August 2, 2004 1:32 AM   Subscribe

Firefox / Javascript question... how do I get the mouse X/Y position across frames (relative to the browser window, of course)

Say I've got a frameset like
--------|    | ||    | |--------
Now if I have a document.onmousedown = someFunction and then have function someFunction(e), then the event 'e' will have e.clientX and e.pageX which hold the current mouse position relative to that frame. If I'm in the right frame though, then I'd need to add the width of the left frame to get the position relative to the browser window.

Is there some way to get the mouse position outside the frames, or without an 'e'? It's been driving me bonkers.
posted by holloway to Computers & Internet (3 answers total)
 
would parent.whatever or window.whatever do what you want? document.whatever will keep you trapped inside that frame.

I'm assuming you don't need the "frames are evil" speech. ;)
posted by twine42 at 3:36 AM on August 2, 2004


Seems like the best strategy would be to do as you suggest and add the width of the left frame to infer the xPos relative to the browser window. If either frame has an exact width, the math is trivial. But even if both are percentages, you can calculate a variable onResize that you can plug into your onmousedown function.

Another idea, totally unsupported by any investigation on my part... can you embed the function in the frameset, rather than the frame?
posted by Jeff Howard at 7:37 AM on August 2, 2004


Have to admit I haven't done much research, but I suspect what you want to do isn't possible. I don't think the js interpreter has any way of knowing about the mouse position relative to other window instances, but rather only within an individual frame. If you really need this, then adding widths is likely the best way to go. Don't see any reason not to put someFunction in the frameset document and use parent.someFunction() to call it, though, if you want to use a little abstraction. Or just keep it all separate in a .js file, of course.
posted by normy at 8:07 AM on August 2, 2004


« Older How long does it take to fall ...   |  I've just bought and installed... Newer »
This thread is closed to new comments.