![](/img/trans.png)
[英]chrome.tabs.create in popup.html is opening infinite number of tabs. How to open one tab?
[英]How to add current tab url to chrome.tabs.create url
我在Chrome中添加了一個conext菜單,當單擊該菜單時,會使用chrome.tabs.create打開Wufoo表單。 我需要用戶以wufoo形式填寫的字段之一是當前選項卡的URL。 因此,我可以簡單地將var a廣告到url,然后將其添加。 如果var a只是一些文本,則此方法有效,但是當我嘗試添加當前選項卡URL時,會將“ undefined”添加到URL。 我怎么了 如何獲取要添加的標簽網址?
這是JavaScript
chrome.contextMenus.onClicked.addListener(function(info, tabs){
var a = chrome.tabs.query({'active': true, 'windowId':chrome.windows.WINDOW_ID_CURRENT},
function(tabs){
return(tabs[0].url);
}
);
if ( info.menuItemId === 'Add a Link' )
chrome.tabs.create( {url: "https://ownthistown.wufoo.com/forms/m3u64zc05w2a0a/def/field10=" + a });
您不能從這樣的內部函數使用返回變量。 你將不得不做這樣的事情
chrome.contextMenus.onClicked.addListener(function(info, tabs){
chrome.tabs.query({'active': true}, function (tabs) {
if(info.menuItemId === 'Add a Link')
chrome.tabs.create({url: "https://ownthistown.wufoo.com/forms/m3u64zc05w2a0a/def/field10=" + tabs[0].url });
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.