Moving focus between document and inline frame

Dan Tsimbala <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
Hi!

Is this a behavior by design:

Here is the test case:

<html>
    <head>
        <script>
            function start_test() {
                var oElement = document.getElementById("iframe_test");
                var oDocument = oElement.contentWindow.document;
                oDocument.designMode = 'on';

                document.addEventListener("focus", function(event) {
                    console.log("outer document", event, event.target,
event.type);
                }, true);
                document.addEventListener("blur", function(event) {
                    console.log("outer document", event, event.target,
event.type);
                }, true);
                oDocument.addEventListener("focus", function(event) {
                    console.log("inner document", event, event.target,
event.type);
                }, true);
                oDocument.addEventListener("blur", function(event) {
                    console.log("inner document", event, event.target,
event.type);
                }, true);
            }
        </script>
    </head>
    <body onload="start_test();">
        <input type="text" id="first">
        <input type="text" id="second">
        <iframe src="unit_iframe.html" id="iframe_test"></iframe>
    </body>
</html>

When focus goes from the input (or any focusable element in the document) to
the IFrame I get the following events chain:

outer document, blur, <input id="second" type="text">
outer document, focus, Document unit.html
outer document, blur, Document unit.html
inner document, focus, Document unit_iframe.html

When focus goes from IFrame to the input I get the following events chain:

inner document, focus, Document unit_iframe.html
inner document, blur, Document unit_iframe.html
outer document, focus, Document unit.html
outer document, focus, <input id="second" type="text">

So document recieves the focus before it is moved to other document or gets
it first when recieving it from other document?

How then to solve the situation when I need to know when focus circulates
between iframe and input and when it goes to some other element? In this
case focus always goes to the main document first and I don't see a good way
to detect when to ignore that. Is there any property reflecting focused
document?

Thanx in advance!
Dan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.