Greasemonkey + jQuery:在事件回调中使用GM_setValue() [英] Greasemonkey + jQuery: using GM_setValue() within an event callback

查看:183
本文介绍了Greasemonkey + jQuery:在事件回调中使用GM_setValue()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在GreaseMonkey脚本中长期存储数据,除了GM_setValue()似乎默默地失败:

I'm trying to set data in long-term storage in a GreaseMonkey script, except that GM_setValue() seems to fail silently:

$("a#linkid").click(function()
{
    GM_setValue("foo", 123); // doesn't work, but does not generate error
});

GM_setValue("bar", 123); // works properly, value is set


推荐答案

我认为这是一个具体的Greasemonkey安全问题。请参阅 0.7.20080121.0兼容性。 GM不允许用户页面调用GreaseMonkey API,这就是您正在做的(您正在使用用户上下文中运行的JQuery注册点击处理程序)。该页面也给出了解决方法。

I think this is a specific Greasemonkey security issue. Please see 0.7.20080121.0 compatibility. GM does not allow user pages to call GreaseMonkey APIs, and that's what you're doing there (you're registering a click handler with JQuery running in the user context). A workaround is also given on that page.

这篇关于Greasemonkey + jQuery:在事件回调中使用GM_setValue()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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