GM_openInTab(或任何其他GM_函数)未定义? [英] GM_openInTab (or any other GM_ function) is not defined?

查看:699
本文介绍了GM_openInTab(或任何其他GM_函数)未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的GM脚本执行此操作时:

When my GM script does this:

var curTab = GM_openInTab(url);

它在浏览器控制台中导致'GM_openInTab is not defined' JavaScript错误.

it results in a 'GM_openInTab is not defined' JavaScript error in the Browser Console.

我也尝试使用var curWin = window.open(url);代替GM_openInTab,但是没有任何影响.

I also tried using var curWin = window.open(url); instead of GM_openInTab but it had no affect.

我要使用此GM脚本进行的操作是:对于给定的网站(域名),遍历该域上的URL列表(数组)并查找感兴趣的项目.

What I'm trying to do with this GM script is: for a given website (domain name), go through a list (array) of URLs on this domain and look for items of interest.

我的代码或方法有什么问题?

What's wrong with my code or approach?

我将Greasemonkey 2.3与Firefox 33.1.1和Windows XP 32位一起使用.

I'm using Greasemonkey 2.3 with Firefox 33.1.1 and Windows XP 32-bit.

推荐答案

为了使用任何GM_函数,必须设置匹配的

In order to use any of the GM_ functions, you must set a matching @grant directiveDoc (As of Greasemonkey version 2.0Release notes)

例如:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    GM_openInTab
// ==/UserScript==

var curTab  = GM_openInTab ("http://pwnthemall.com/");

请注意,这会重新打开Greasemonkey的沙箱具有副作用.另请参阅:

Note that this has the side effect of switching Greasemonkey's sandbox back on. See also:

  • Error: Permission denied to access property 'handler'
  • How to access `window` (Target page) objects when @grant values are set?

Tampermonkey 模仿

Tampermonkey emulates most of this behavior as of version 3.9Release notes. But the current version (3.9.202) still attempts to guess appropriate values if @grant is not specified, so you won't necessarily see an error (yet).
Always use @grant anyway, for maximum compatibility and to future-proof your code.

这篇关于GM_openInTab(或任何其他GM_函数)未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆