2011-07-27 7 views
0

自分のアドオンの開発中にこの問題が発生しましたが、redditの例でも同じことが起こります。Mozilla Addon SDK - 2ページ目のRedditの問題

hereの例の正確なコードを使用すると、これが起こります。

Redditの例

この例では、アドオンのRedditのモバイルバージョンを含むパネルを作成します。ユーザーがパネル内のストーリーのタイトルをクリックすると、アドオンはリンクされたストーリーをメインブラウザーウィンドウの新しいタブで開きます。

これを達成するには、各タイトルリンクのマウスクリックをインターセプトしてリンクのターゲットURLを取得するRedditページのコンテキストでコンテンツスクリプトを実行する必要があります。コンテンツスクリプトはURLをアドオンスクリプトに送信する必要があります。

main.js:

var data = require("self").data; 

var reddit_panel = require("panel").Panel({ 
    width: 240, 
    height: 320, 
    contentURL: "http://www.reddit.com/.mobile?keep_extension=True", 
    contentScriptFile: [data.url("jquery-1.4.4.min.js"), 
        data.url("panel.js")] 
}); 

reddit_panel.port.on("click", function(url) { 
    require("tabs").open(url); 
}); 

require("widget").Widget({ 
    id: "open-reddit-btn", 
    label: "Reddit", 
    contentURL: "http://www.reddit.com/static/favicon.ico", 
    panel: reddit_panel 
}); 

panel.js:

$(window).click(function (event) { 
    var t = event.target; 

    // Don't intercept the click if it isn't on a link. 
    if (t.nodeName != "A") 
    return; 

    // Don't intercept the click if it was on one of the links in the header 
    // or next/previous footer, since those links should load in the panel itself. 
    if ($(t).parents('#header').length || $(t).parents('.nextprev').length) 
    return; 

    // Intercept the click, passing it to the addon, which will load it in a tab. 
    event.stopPropagation(); 
    event.preventDefault(); 
    self.port.emit('click', t.toString()); 
}); 

アイコンがバーに表示され、それをクリックすると、パネルを起動しています。パネル内のリンクをクリックすると、そのリンクが新しいタブで開かれます。

タブ内の「次のページ」リンクをクリックすると、パネル内の次のページが正常にフェッチされます。

2番目のページのリンクをクリックしても、タブで開くことはできません。パネル内でリンクを開きます。

私の推測です:パネル内でページがリロードされると、contentScriptFileで指定されたスクリプトがリロードされません。他の誰かがこれを経験していますか?回避策はありますか?

私は、Mozillaのフォーラムで、SDK 1.0およびFF 5.0

質問アドオンフォーラムhere

答えて

0

にクロスポスト受け取っthis answerを使用していて、今後の参考のためにもここに掲載します。

おそらくBug 667664 - Panel content scripts don't work after reloading or changing locationが表示されています。回避策は、iframeにコンテンツを読み込むことだと思います。

これは私がそのように思うかもしれないが、私はその日中にこれを試して、報告します。

EDIT: iframeと思われる