Solved

How to get mouse event to work over the iframe??

Posted on 2004-08-03
6
663 Views
Last Modified: 2008-03-17
I've been working on it all day with no luck then I figured that I need help.  What I have here is an mouse event that would work outside of the iframe but not over it.  I am wondering if it is possible to have a mouse event that can detect the mouse position either over or inside of the iframe and get a fix on it or something.   Whatever it it, I'll accept your wild idea on making this possible.

Thanks,
 FletchSOD
0
Comment
Question by:fletchsod
  • 2
  • 2
6 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 125 total points
Comment Utility
Which mouse event are you talking about?

onmousemove on the main page doesn't work on iframe. If you want the mouse position over the iframe compared to the whole screen, put this code in the <body> tag of the iframe:

<body onmousemove="alert(event.screenX+','+event.screenY);">

Then, in your main page with the iframe, have the same code in the <body>. This should definitely work for both over iframe and over main page, although you'd probably want to store the value into a variable instead of alerting (if you get stuck in an alert loop, move you mouse off the window. Press Enter, then do AltF4)

Regards,
${Zyloch}
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
Comment Utility
How about this:

<html>
<head>
<script>
var msgDiv;
function moveMouse(){
  e = window.frames.myFrame.event;
  msgDiv.innerHTML = e.x+":"+e.y;
}
function init(){
  msgDiv = document.getElementById("mPos");
  window.frames.myFrame.document.body.onmousemove=moveMouse;
}
</script>
</head>
<body>
<div id="mPos"></div>
<iframe name="myFrame" src="mypage.htm" onLoad="init()"></iframe>
</body>
</html>


0
 

Author Comment

by:fletchsod
Comment Utility
Yes, it had to do with the onmousemove events.  Both examples are good enough for me.  I can take it from there.  

Thanks, FletchSOD
0
 

Author Comment

by:fletchsod
Comment Utility
Rat!  I'm trying to pick one as accept answer with 125 points and the other as assist answer with 125 points also.  Where's that community forum where I can ask the administrator to fix it for me??  Thanks. Scott
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now