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

查看:475
本文介绍了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天全站免登陆