tags:

views:

79

answers:

3

I have a function that i need to call on iframe mousemove(). But i didnt found anything like we have in body tag We have <body mousemove="Function()"> Do we have anything like this for iframe??

A: 

Dupe of http://stackoverflow.com/questions/1641053/call-function-on-mousemove ?

See @David Caunt's response.

Andrei Serdeliuc
This is a comment. Also, not a dupe, `<iframe>`s are special.
Kobi
A: 

Did you mean onMouseOver or onFocus?

e.g.

<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>  
  <script language="javascript">
  <!--
function SayHello()
{
 alert("Hi from IFrame");
}

  //-->
  </script>
 </HEAD>

 <BODY>
 <iframe id="myiFrame" onMouseOver="SayHello()"/>
<iframe id="myiFrame" onFocus="SayHello()"/>
 </BODY>
</HTML>
priyanka.sarkar
Yes I mean same like this.
Talha Bin Shakir
+1  A: 

The iframe contains its own document, own body element etc. Try something like this:

var frame = document.getElementById("yourIframeId");
// IE is special
var frameDoc = frame.contentDocument || frame.contentWindow.document;
var frameBody = frameDoc.getElementsByTagName("body")[0];

var testingOneTwo = function() {
    console.log("Hello, is this thing on?");
};
frameBody.onmouseover = testingOneTwo;
nlogax
But Where I should put this code. is it put inside the iframe tag ?? or should put it inside my main page <script>tag</script>. I really confusing too much. Please can you more elaborate.
Talha Bin Shakir
This would be in the main page, as I assumed you wanted it. You can of course just put it directly in the document that is loaded in the iframe.Oh, remember to wait for onload (or put the `<script>` at the bottom) if you try the script, so that it can find the `<iframe>` when it runs.
nlogax
Oh, if you put it in the document that is loaded in the iframe, it should be just like any other document, you should be able to do `<body onmousemove="foo()">` and so on.
nlogax