如何检查特定页面是否已在Google Chrome浏览器中打开? [英] How to check if a specific page is already open in Google Chrome?

查看:75
本文介绍了如何检查特定页面是否已在Google Chrome浏览器中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个打包的Web应用程序,我希望能够在加载时检查该Web应用程序是否还有其他打开的实例,如果有,则切换到打开的实例比创建另一个.

Basically, I've got a packaged web application which I'd like to be able to check as it loads if there are any other instances of the web application open, and, if so, to switch to the open instance rather than create another one.

此外,对于选项页面,我希望它能够检查应用程序是否打开,如果可以,请在更改了选项页面的情况下刷新应用程序页面.

Also, for the options page, I'd like it to be able to check if the application is open, and, if so, refresh the application page if the options page has been changed.

我一直在阅读有关chrome的文档.tabs JavaScript模块,但是我不知道如何使函数查找特定的标签.我不太了解如何查找或设置特定标签的标签ID.我认为这是我想要的方法,但是如果我吠错了树,请告诉我.

I've been reading the documentation about the chrome.tabs JavaScript module, but I can't work out how to make the function look for a specific tab. I don't quite understand how to look for or set the tab ID for a specific tab. I think this is how to do what I want, but if I'm barking up the wrong tree please let me know.

如果这里有人可以更好地为我解释,我将非常感激.

If anyone here can explain it better for me I'd be most thankful.

推荐答案

查看 Google Mail Checker 扩展程序,它具有以下功能:

Look inside the Google Mail Checker extension, which has this functionality:

function goToInbox() {
  chrome.tabs.getAllInWindow(undefined, function(tabs) {
    for (var i = 0, tab; tab = tabs[i]; i++) {
      if (tab.url && isGmailUrl(tab.url)) {
        chrome.tabs.update(tab.id, {selected: true});
        return;
      }
    }
    chrome.tabs.create({url: getGmailUrl()});
  });
}

特别是,您将窗口ID(或当前窗口的未定义)和getAllInWindow传递给一个函数,该函数接收Tab对象的数组.您不直接修改选项卡的属性;而是直接修改选项卡的属性.而是将其ID传递给update函数以便对其进行操作.

In particular, you pass getAllInWindow the windowId (or undefined for the current window) and a function, which receives the array of Tab objects. You don't modify the properties of the tab directly; rather you pass its id to the update function in order to manipulate it.

这篇关于如何检查特定页面是否已在Google Chrome浏览器中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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