用Java检查子窗口焦点 [英] Check Child Window Focus in Javascript

查看:50
本文介绍了用Java检查子窗口焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道用户是否关注http或https.

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".

我检查了W3C.页面可见性API

I checked the W3C. The Page Visibility API

是有没有一种方法可以检测浏览器窗口当前是否未激活?

但是对我来说,它仅适用于选项卡,而不适用于Windows.

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

并且仅在父窗口中进行了测试.

有帮助吗?

谢谢.

这就是我得到的.

<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>

打开窗口并设置一次位置后,事件会在Chrome中触发2次.href已设置...但此后什么都没有

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

推荐答案

尝试将代码放入div,将div放入表格中,然后将表格放在顶部框架中!!

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

这篇关于用Java检查子窗口焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆