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

ぐ巨炮叔叔 提交于 2019-12-24 00:53:02

问题


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(the page that the popup window holds)

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

回答1:


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

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.



来源:https://stackoverflow.com/questions/23180404/how-to-get-window-id-of-the-popup-window-that-is-created-by-chrome-windows-creat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!