admin管理员组文章数量:1389204
i am making a bookmarklet in the bookmarklet i am adding a iframe to the page's body.
i need to find the current mouse position to position the iframe accordingly.
The issue is. i cannot bind on click for the bookmarklet because by the time the script within the href="javascript:"
runs the click was already done. so i cannot get the event there.
i thought of binding mousemove
, but that's a ugly workaround.
so is there a way to get mouse's current x/y ? without an event firing ?
Thanks.
i am making a bookmarklet in the bookmarklet i am adding a iframe to the page's body.
i need to find the current mouse position to position the iframe accordingly.
The issue is. i cannot bind on click for the bookmarklet because by the time the script within the href="javascript:"
runs the click was already done. so i cannot get the event there.
i thought of binding mousemove
, but that's a ugly workaround.
so is there a way to get mouse's current x/y ? without an event firing ?
Thanks.
Share Improve this question edited Jan 18, 2014 at 14:53 danronmoon 3,8735 gold badges35 silver badges58 bronze badges asked Jan 18, 2014 at 13:50 Neta MetaNeta Meta 4,03710 gold badges47 silver badges71 bronze badges 14- Check the accepted answer on this question. Is that helping you out? – Mandy Schoep Commented Jan 18, 2014 at 14:08
-
Can't you put the code of getting the position in your
href="javascript:"
function? – Mandy Schoep Commented Jan 18, 2014 at 14:10 - No there's no way to get mouse position without triggering one of the MouseEvent. – Givi Commented Jan 18, 2014 at 14:15
- Mouse up is a no go, we are way past click event when the script executes. @roy how? – Neta Meta Commented Jan 18, 2014 at 14:17
- 2 Even if there were a way to get mouse cursor position without an event firing (almost positive there isn't), the cursor will be outside of the viewport anyway when the user clicks a bookmarklet, and events that report mouse position don't fire when the cursor is outside of the viewport. IOW mouse positions outside of the viewport are never reported, so even without events, you're pretty much out of luck. – Dagg Nabbit Commented Jan 18, 2014 at 18:42
2 Answers
Reset to default 2Javascript is a language to add client side functionality on user interaction. Therefore, a javascript code snippet is always run as response to an event.
I would suggest using the onmousemove
event. The event would be raised each time the cursor mouse would change. Therefore, you will know the mouse position at all times.
Hope I helped!
Have you tried something like setTimeOut()? As far as I can tell you, there is no way to see the mouse position without using an Event object to do that.
Please, take a look at this thread:
Javascript - Track mouse position
本文标签: javascriptis there a way to find mouse current position on the screen without an eventStack Overflow
版权声明:本文标题:javascript - is there a way to find mouse current position on the screen without an event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744555994a2612477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论