简体   繁体   English

如何将当前标签页网址添加到chrome.tabs.create url

[英]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.

相关问题 popup.html中的chrome.tabs.create正在打开无限数量的标签。 如何打开一个标签页? - chrome.tabs.create in popup.html is opening infinite number of tabs. How to open one tab? 如何使用chrome.tabs.create从新创建的chrome选项卡中获取元素文本 - How to get an element text from a newly created chrome tab using chrome.tabs.create chrome.tabs.create不起作用 - chrome.tabs.create not working Chrome扩展程序:在新标签中创建新标签(chrome.tabs.create)和executeScript ...无法正常工作:( - Chrome Extension: create new tab(chrome.tabs.create) and executeScript in new tab…not working :( 如何从chrome.tabs.create传递变量 - how to pass variable from chrome.tabs.create 如何从内容脚本调用chrome.tabs.create API? - How to call chrome.tabs.create API from content script? chrome.tabs.create无法在Chrome启动时使用 - chrome.tabs.create not working on Chrome startup 我正在尝试使用 chrome.storage.sync 和 chrome.tabs.create 传输用户输入的数据并将其用作 chrome.tabs api 的 url - I am trying to use chrome.storage.sync and chrome.tabs.create to transfer data that user inputed and use it as the url for chrome.tabs api chrome.tabs.create无法正常工作? - chrome.tabs.create not working properly? 不会在弹出窗口中触发chrome.tabs.create的回调吗? - Callback of chrome.tabs.create is not triggered in a popup?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM