[英]How to add current tab url to chrome.tabs.create url
I have added a conext menu in Chrome that when clicked opens a Wufoo form using chrome.tabs.create. 我在Chrome中添加了一个conext菜单,当单击该菜单时,会使用chrome.tabs.create打开Wufoo表单。 One of the fields I need the user to complete in the wufoo form is the URL of the current tab.
我需要用户以wufoo形式填写的字段之一是当前选项卡的URL。 So I can simply ad my var a to the url and it should be added.
因此,我可以简单地将var a广告到url,然后将其添加。 This works if var a is just some text but when I try to add the current tab url "undefined" is added to the url.
如果var a只是一些文本,则此方法有效,但是当我尝试添加当前选项卡URL时,会将“ undefined”添加到URL。 What is my mistake?
我怎么了 How do I get the tab url to be added?
如何获取要添加的标签网址?
Here is the javascript 这是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 });
You cannot use return variable from an inner function like that. 您不能从这样的内部函数使用返回变量。 You will have to do something like this
你将不得不做这样的事情
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.