Hello,
I have a main html page which creates an iframe, something like:
Now, the above iframe has for example this in it:
I want to add an event to the links from this iframe from my main page like this:
window.frames[0] refers to the first frame (assuming that's the above). In the above line I am assigning the first anchor in the iframe the onmousemove attribute and tell it to execute the function Functi when a user moves the mouse over that link in the iframe.
This works almost well. The function is called but the problem is that I need to operate on the event that's generated and hence need a reference to it.
The function Functi looks something like: and it is declared in the main html page:
Now, the problem is how can I correctly pass the 'event' that happened in the iframe to the function Functi?
I am sure that the problem lies somewhere with the iframes because assigning exactly in this same way the onmousemove attribute to a link in my main page works perfectly fine. So, this works well:
The above will give the onmouseover property to the second anchor in my main page, and when I hover over it, it calls the function and accesses the 'event' without problems.
I tried doing something like:
But it doesn't help.
The error I get when I hover over the link in my iframe is: "Object expected" on the line that tries to access the event in the function Functi.
Thanks in advance for your replies.
I have a main html page which creates an iframe, something like:
Code:
<iframe id='somefrm' src="http://somepage/frm.html" title="My frame" name='somefrm' frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 34%;">text</iframe>
Code:
<body> <a href="http://msn.com">First link inside my frm.html</a><br /> <a href="http://msn.ca">Second link inside my frm.html</a><br /> </body>
Code:
window.frames[0].document.getElementsByTagName('a')[0].onmousemove=Functi;
This works almost well. The function is called but the problem is that I need to operate on the event that's generated and hence need a reference to it.
The function Functi looks something like: and it is declared in the main html page:
Code:
function Functi(e) {
if (!e) var e = window.event;
// operate on e
}
I am sure that the problem lies somewhere with the iframes because assigning exactly in this same way the onmousemove attribute to a link in my main page works perfectly fine. So, this works well:
Code:
document.getElementsByTagName("a")[1].onmouseover=Functi;
I tried doing something like:
Code:
window.frames[0].document.getElementsByTagName('a')[0].onmousemove=function(){Functi(event);};
The error I get when I hover over the link in my iframe is: "Object expected" on the line that tries to access the event in the function Functi.
Thanks in advance for your replies.
Comment