如何获取由chrome.windows.create()创建的弹出窗口的窗口ID [英] How to get window id of the popup window that is created by chrome.windows.create()

查看:2723
本文介绍了如何获取由chrome.windows.create()创建的弹出窗口的窗口ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得由chrome.windows.create()创建的弹出窗口的窗口标识()

How to get window-id of the popup window that is created by chrome.windows.create()

background.html

window_options={
"url":"another_popup.html"
"type":"popup"
};

chrome.windows.create(window_options,call_back_function)
call_back_function(Window window)
{
console.log(window.id) 
//prints the window's id properly
}

another_popup.html弹出窗口包含)

$(document).ready(function()
 {
console.log(window.id)
//says ,cannot find property and gives a null 
 });


推荐答案

JavaScript中没有像window.id这样的属性。但是,在使用chrome API(chrome.windows.create)时,在回调函数中有这样的属性,但它与javascript本身没有关联(javascript无法识别内部浏览器的标识系统)。

There is no such property like window.id in javascript. However, you have such property in a callback function when using chrome API (chrome.windows.create) but it is not associated with javascript itself (javascript does not recognize internal browser's identification system).

可以使用内部扩展范围,例如 chrome.tabs.getCurrent 方法来检索有关当前选项卡的信息。在回调函数中,您将拥有一个ID。请注意,该ID是可选的,可能不会设置。

Inside extension scope you can use for example chrome.tabs.getCurrent method to retrieve information about current tab. In a callback function you'll have an id. Note that the id is optional and may not be set.

这篇关于如何获取由chrome.windows.create()创建的弹出窗口的窗口ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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