0
我想訪問使用Firefox擴展的youtube上的評論部分。由於評論部分位於iframe中,並且位於其他網站(plus.googleapis.com)上,因此我需要啓用跨域功能。Firefox附加SDK和跨域
我這樣做,通過在的package.json跨域內容:
{
"name": "testfirefoxextension",
"title": "testFirefoxExtension",
"id": "id removed",
"description": "nike z youtubu v zvezi",
"author": "kv1dr",
"license": "MPL 2.0",
"version": "0.1",
"permissions": {
"cross-domain-content": ["http://www.youtube.com", "https://plus.googleapis.com/"]
}
}
以防萬一,在lib/main.js
我既增加youtube.com和googleapis.com包括部分。這是lib/main.js
的全部內容:
// Import the page-mod API
var pageMod = require("sdk/page-mod");
// Import the self API
var self = require("sdk/self");
// Create a page mod
// It will run a script whenever a "youtube.com" URL is loaded
// The script replaces the page contents with a message
pageMod.PageMod({
include: ["*.youtube.com","*.googleapis.com"],
contentScriptFile: [self.data.url("jquery-2.1.1.min.js"), self.data.url("youtube.js")]
});
在youtube.js我alert($("#comments-test-iframe").html());
只是爲了測試,如果跨域腳本工作,但當評論加載中,腳本顯示了空消息,但是當評論被加載,腳本顯示[未定義],而不是評論部分的內容。爲什麼?以及如何獲取iframe內容?
我們可以看到更多的youtube.js嗎?難道是因爲你錯過了「http://www.youtube.com」'中的最後'/'。是否因爲youtube在'https'? – willlma 2014-09-25 21:55:11
這些都來自yotube.js。我沒有添加任何其他內容,因爲即使這樣也行不通。是的,我也嘗試在YouTube鏈接末尾添加斜線,並且我在YouTube的非SSL(http)頁面上測試了此擴展程序,但它仍然無效。 – kv1dr 2014-09-25 22:07:22
「當註釋加載時,腳本顯示[未定義]。」等待評論加載的代碼在哪裏? – willlma 2014-09-25 23:50:40