Check Child Window Focus in Javascript
Asked Answered
K

1

0

I want to know if the user has focus on the http or https.

So everytime the user clicks on one of the childwindows - i want to know which one is "active".

I checked the W3C. The Page Visibility API

Is there a way to detect if a browser window is not currently active?

But for me it only was working with tabs but not windows.

EDIT: And only tested on the Parentwindow.

Any Help?

Thanks in advance.

Here is what i got.

<html>
<head>
    <title>checkfocus</title>
</head>
<body>
<a href="javascript:loadChild()">Click me</a>.
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
    var w;
    var w2;
    function loadChild() {

        w = window.open("","",'width=400,height=200');
        w.location.href="https://www.facebook.com";
        w.moveTo(0,0)
        w.addEventListener('focus',function(){
            console.log("w")
        })


        w2 = window.open("","",'width=400,height=200');
        w2.moveTo(400,0)
        w2.location.href="http://www.facebook.com";
        w2.addEventListener('focus',function(){
            console.log("w2")
        })
    }

</script>
</body>
</html>

the Events is fired 2 times in chrome one time when the window is opened and one time location.href is set... but nothing afterwards

Kauppi answered 7/6, 2013 at 22:31 Comment(4)
why dont you set and unset a common flag on click of parent and child!!Pestalozzi
didn´t worked as well on childrenKauppi
the problem is on the child no event is triggeringKauppi
a friend of mine told me now ... after you add href property to the window you can´t access any more events from this window .. this is true while i tried same code without setting href property and it worked.... anybody knows some workaround?Kauppi
R
0

try to put the code in a div, put the div in a table and put the table in a top-frame...!

Rajput answered 9/6, 2013 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.