jquery如何检查所选的浏览器选项卡/窗口是否在我们的页面上? [英] jquery how to check if browser tab/window the selected is on our page?

查看:55
本文介绍了jquery如何检查所选的浏览器选项卡/窗口是否在我们的页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查用户目前是否在我们的页面上显示浏览器的标签/窗口

How do check if a the user has the browser's tab/window currently on our page

function userisonourpage()
{
//do something
}

当用户切换时选项卡/窗口到我们的页面?

And when a user switches the tab/window to our page ?

function tabswitched()
{
//dom something here too
}

就像在很多地方一样,你切换到页面,标题改变我知道标题可以改为: document.title
但不知道如何实现这些功能。

Just like in many places u switch to the page and the title changes i know the title can be changed with : document.title but dont know how to implement those functions.

谢谢:D

推荐答案

你可以这样做:

$(document).ready(function(){
   $([window, document]).focusin(function(){
      //Your logic when the page gets active
   }).focusout(function(){
      //Your logic when the page gets inactive
   });
});

希望这会有所帮助。干杯

Hope this helps. Cheers

这篇关于jquery如何检查所选的浏览器选项卡/窗口是否在我们的页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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