javascript - 从 Greasemonkey 调用时,jQuery UI 对话框会抛出错误

标签 javascript jquery greasemonkey

每当我尝试创建一个对话框时,我都会遇到这个尴尬的错误 Greasemonkey...我相信这与限制有关 XPCNativeWrapper https://developer.mozilla.org/en/XPCNativeWrapper#Limitations_of_XPCNativeWrapper ,尽管我不是 100% 确定。

我使用的核心 jQuery 方法都没有导致错误 (附加,CSS,提交,keydown,每个,...)。

这可能是 Greasemonkey 中的错误或由于 Greasemonkey和jquery ui的交互,不过我真的 有兴趣弄清楚如何让他们一起工作。

// ==UserScript==
// @name           Dialog Test
// @namespace      http://strd6.com
// @description    jquery-ui-1.6rc6 Dialog Test
// @include        *
//
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// @require        http://strd6.com/stuff/jqui/jquery-ui-personalized-1.6rc6.min.js

// ==/UserScript==

$(document).ready(function() {
 $('<div title="Test">SomeText</div>').dialog();
});

错误: [异常...“组件不可用”nsresult:“0x80040111 (NS_ERROR_NOT_AVAILABLE)”位置:“JS框架:: 文件:///home/daniel/.mozilla/firefox/.../components/greasemonkey.js:: 匿名::第 347 行”数据:否] [中断此错误] if (line) {

火狐版本: Mozilla/5.0(X11;U;Linux i686;en-US;rv:1.9.0.6)Gecko/2009020911 Ubuntu/8.04(耐寒)Firefox/3.0.6

更新:标准 jQuery 库中的 focus() 方法也会引发相同的错误:

$('body').focus();

也许 UI 在某个时刻调用了 focus 方法?

任何帮助将不胜感激!

最佳答案

这个线程已经很老了,但是使用 Greasemonkey 和 Jquery 来 focus() 的方法是将 [0] 添加到 jquery 对象以将其返回到 DOM 元素。

      //Example:  
      $('#obj').focus();                          //Does not work
      document.getElementById('obj').focus();     //Works

      //Hybrid:
      $(#obj)[0].focus();                         //Work around

关于javascript - 从 Greasemonkey 调用时,jQuery UI 对话框会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/564342/

相关文章:

javascript - 我需要使用 JavaScript 或 HTML 链接到当前 HTML 页面中的另一个 HTML 页面

Javascript/Jquery - 在函数中设置默认值

javascript - 如果找到字符串如何发出警报

javascript - 为什么 waitForKeyElements() 尽管后来发生了变化,但只触发一次?

javascript - 如何使多个 Collapse 处于动态状态

javascript - 如何在buttonClicked上调用$ionicActionSheet之外的函数?

javascript - 如何取消js文件的压缩?

php - 使用 GA、jQuery 和 PHP 跟踪文件下载

javascript - 在 Greasemonkey 上使用 javascript 单击图像/函数?

javascript - Bootstrap - 如何制作固定宽度/不可滚动但仍然响应的垂直侧边栏?