0

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'm 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?

4

3 に答える 3

0

目的の iframe にラッパーの fireevent メソッドを作成し、そのラッパー メソッドから windows fireevent を呼び出すことができます。

これ以外の iframe からこのラッパーを呼び出します。目的の iframe でイベントが発生します。

于 2013-10-09T07:54:31.643 に答える
0

iframe に架空のイベントを作成し、それをターゲットのリンクまたはフレームに添付します。

また、お気づきかもしれませんが、イベントを発生させる方法は、テスト ブラウザーが従う標準によって異なります。

 // Attach the fictive event object to the target
    // MSIE
    if (document.createEventObject )
        YourTarget.fireEvent('onmouseup',oEvt) ;
    // W3C
    else
        YourTarget.dispatchEvent(oEvt) ;

Plsはここで詳細を参照してください

あなたの必要性を完全に理解しているかどうかわからないので、それが役立つか、少なくともヒントを与えてくれることを願っています.

于 2012-04-16T15:20:59.337 に答える
0

この問題の解決策は、postMessage を使用する HTML5 です。

ここで例を見つけました: http://robertnyman.com/html5/postMessage/postMessage.html

于 2012-04-17T21:04:21.590 に答える