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??
views:
79answers:
3
A:
Dupe of http://stackoverflow.com/questions/1641053/call-function-on-mousemove ?
See @David Caunt's response.
Andrei Serdeliuc
2009-11-08 08:32:58
This is a comment. Also, not a dupe, `<iframe>`s are special.
Kobi
2009-11-08 08:37:07
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
2009-11-08 08:48:42
+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
2009-11-08 09:13:19
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
2009-11-08 11:38:07
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
2009-11-08 11:48:06
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
2009-11-08 11:49:20