Chrome扩展脚本

詹姆士

我创建了一个chrome扩展程序,该扩展程序将在文本突出显示上找到USPS跟踪号。我当前的代码运行良好,但我想进行一些修改。

这是manifest.json

{
  "manifest_version": 2,
  "background" : { "scripts": ["background.js"] },
  "description": "Track on USPS",
  "icons": {
  "default_icon": "usps.png"
      },
  "minimum_chrome_version": "29.0", 
  "name": "USPS",
  "permissions": [ "contextMenus", "tabs", "http://*/*",
  "https://*/*" ],
  "version": "1.0"
}

这是background.js:

/**
* Returns a handler which will open a new tab when activated.
*/
function searchgoogle(info)
{
  var searchstring = info.selectionText;
  chrome.tabs.create({url: "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=" + searchstring})
}

chrome.contextMenus.create({title: "Search USPS", contexts:["selection"], onclick: searchgoogle});

/**
* Create a context menu which will only show up for images.
*/
chrome.contextMenus.create({
  "title" : "Search tracking number on USPS",
  "type" : "normal",
  "contexts" : ["text"],
  "onclick" : getClickHandler()
});

现在,我想修改当前脚本:

https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=" + searchstring

使用下面的脚本。此新代码将打开一个弹出窗口。我尝试修改新脚本,但无济于事。谁能帮我吗?

这是我想使用的新脚本:

javascript:new function(){window.open('https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=' + window.getSelection().toString(), '_blank', 'toolbar=0,location=0,menubar=0,top=91,height=900,width=650,left=1475');};

在此先多谢!这个社区对我的项目有很大帮助。

蒂莫西·也许

看起来您实际上并没有在脚本中调用正在创建的函数(并且不能,因为它没有命名)。尝试删除该函数,然后仅执行代码:

javascript:window.open('https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=' + window.getSelection().toString(), '_blank', 'toolbar=0,location=0,menubar=0,top=91,height=900,width=650,left=1475');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章