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