2009-02-19 33 views
2

我得到這個尷尬的錯誤任何時候我嘗試從 的Greasemonkey創建一個對話框時調用......我相信它有做的 XPCNativeWrapper https://developer.mozilla.org/en/XPCNativeWrapper#Limitations_of_XPCNativeWrapper 的限制,雖然我我不是100%確定的。jQuery UI的對話框拋出錯誤當從Greasemonkey的

我使用的核心jQuery方法都沒有引起錯誤 (append,css,submit,keydown,each,...)。

這是可能的,這可能是在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/火狐/.../組件/ greasemonkey.js :: 匿名::管線347" 的數據:無] [該誤差打破]如果(線){

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

更新:從標準的jQuery庫中的焦點()方法也拋出了同樣的錯誤:

$('body').focus(); 

也許UI呼籲在一些點對焦方法?

任何幫助將不勝感激!

回答

2

這個線程相當舊,但使用Greasemonkey和Jquery來focus()的方法是向jquery對象添加一個[0]以將其返回到DOM元素。

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

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

以下是一種解決方法,但仍然存在其他較不顯着的問題。

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

// ==/UserScript== 

// Inject jQuery into page... gross hack... for now... 
(function() { 
    var head = document.getElementsByTagName('head')[0]; 

    var script = document.createElement('script'); 
    script.type = 'text/javascript'; 

    var jQuery = GM_getResourceText('jQuery'); 
    var jQueryUI = GM_getResourceText('jQueryUI'); 

    script.innerHTML = jQuery + jQueryUI; 
    head.appendChild(script); 

    $ = unsafeWindow.$; 
})(); 

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

的問題具有現在從$在unsafeWindow上下文是莖,因此某些GM方法不能被稱爲從不安全的上下文(如GM_getValue當內部$。每次)。必須有一種方法才能達到這個目標,並且可以在Greasemonkey中使用jQueryUI。我90%確定這是一個XPCNativeWrapper問題,所以應該通過更改對話框插件中的一些代碼來實現一個簡單的解決方法。

+0

>>某些GM方法不能從不安全的上下文中調用<<您是否找到了解決方案?我真的很感興趣。 – eWolf 2009-12-22 13:30:05

1

不直接回答,而是:

如果你還沒有結婚的Greasemonkey,但想好了jQuery的整合和在Firefox的Greasemonkey一樣的功能,你應該看看Mozilla Ubiquity。它有內置的jQuery,對瀏覽器窗口的良好訪問,相對於從任意位置加載內容的相對自由度,每頁加載執行選項(la Greasemonkey),外部腳本加載器(這就是我試着加載jQuery UI ..)以及其他一些非常酷的東西。我發現在幾分鐘內玩起來更容易,而不是搞亂GM/Firefox插件的怪異。