Mozilla插件SDK -问题与Reddit的例子在第二页

Mozilla Addon SDK - Problem with Reddit example on 2nd page

本文关键字:二页 SDK 插件 问题 Reddit Mozilla      更新时间:2023-09-26

我在开发自己的插件时遇到了这个问题,但我在reddit的例子中也遇到了同样的问题,所以为了简单起见,我将使用它。

使用这里找到的示例中的确切代码,这就是发生的事情。

Reddit例子

这个示例插件创建了一个包含移动版Reddit的面板。当用户在面板中单击一个故事的标题时,该附加组件将在主浏览器窗口的新选项卡中打开链接的故事。

要完成这个插件需要在Reddit页面的上下文中运行一个内容脚本,该脚本拦截鼠标点击每个标题链接并获取链接的目标URL。然后,内容脚本需要将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());
});

图标将显示在工具栏中,单击它将启动面板。单击面板内的链接将在新选项卡中打开它-正如所描述和期望的那样。

点击选项卡内的"next page"链接成功获取面板内的下一页-如预期的那样。

点击第二页的链接不会在标签中打开它,而是在面板中打开它。

这是我的猜测:当页面在面板中重新加载时,它不会重新加载contentScriptFile中指定的脚本。有人有过这样的经历吗?有解决办法吗?

我使用SDK 1.0和FF 5.0

问题交叉张贴在Addon论坛这里

在Mozilla论坛上收到了这个答案,并将在这里发布以供将来参考。

也许你正在看到Bug 667664 -面板内容脚本在重新加载或更改位置后不工作。我认为解决的办法是在iframe中加载内容。

我相信可能是这样的,我会在白天尝试一下并反馈。

编辑: iframe似乎做的伎俩