Chrome扩展:让chrome.tabs.query()同步 [英] Chrome extensions: make chrome.tabs.query() synchronous
问题描述
我目前使用这种code:
I am currently using this code:
url = "unknown";
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function(tabs) {
console.log(tabs); //test, prints one-element array as expected
url = tabs[0].url;
});
$("#url_div").html(url);
要获取当前的URL,但 chrome.tabs.query()
是 ansynchronous 的,我怎么能使其同步? (即添加非同步:假
地方)
to get current URL, but chrome.tabs.query()
is ansynchronous, how can I make it synchronous? (i.e. add asynch: false
somewhere)
我知道我可以从那里设置的URL的 的查询里面,或者调用另一个函数,但最好是(例子simplifed),如果它不是非同步。
I know I could set the URL inside the query, or call another function from there, but best would be (example is simplifed) if it wasnt asynch.
推荐答案
除非有查询功能,这是不可能的一些隐藏的功能。 http://developer.chrome.com/extensions/tabs.html#method-query
Unless there is some hidden functionality in the query function this is not possible. http://developer.chrome.com/extensions/tabs.html#method-query
这篇关于Chrome扩展:让chrome.tabs.query()同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!