Search code examples
javascriptdom-events

fireEvent from iframe to top.document.body


I have this function:

function doSomething(e) {
    if (!e) var e = window.event;
    alert(e.type);
}

When the HTML (Master.html) page is ready, I'll call this other:

var iniciarTimeOut = function (e) {
    document.onload = doSomething;
    window.onmousedown = doSomething;
    window.onkeypress = doSomething;
};

I have an Iframe into Master.html and I want to detect the event into iframe.html but fire the event in Master.html I'm trying with this:

document.onmousedown = top.document.body.fireEvent("onload");
document.onkeypress = top.document.body.fireEvent("onmousedown");
document.onload = top.document.body.fireEvent("onload");

How can I do it?


Solution

  • The solution to this problem is HTML5 using postMessage.

    I found an example here: http://robertnyman.com/html5/postMessage/postMessage.html