0
xulを使用してFirefoxのアドオンを作成しています。私は次のスクリプトを使用して動的インラインフレームを追加しました:xMを使用してFirefoxのアドオンで動的に追加されたiframeでpostMessageが動作しない
//addon script:
let chromeUrl = 'https://myserver/downloadProduct.html';
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
let mainDocument = activeWindow.document;
let iframeEl;
iframeEl = mainDocument.createElement('iframe');
iframeEl.id = "d";
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
iframeEl.setAttribute('height', '32px');
window.document.documentElement.insertBefore(iframeEl, window.document.documentElement.window);
window.addEventListener("message", receiveMessage,false);
上記のスクリプトが正常にページ上に新しいのiframeを追加しています。今、iframeからアドオンにメッセージを受け取りたい。次のように私は、iframeのスクリプトでスクリプトをのpostMessageイベントを作成しました:
//iFrame Script:
<script type="text/javascript">
$(document).ready(function() {
$("#Download").click(function() {
parent.postMessage({ Action: "DOWNLOADED", Result: null }, "*");
})
$("#NotNow").click(function() {
parent.postMessage({ Action: "NOT_NOW", Result: null }, "*");
})
$("#Never").click(function() {
parent.postMessage({ Action: "DO_NOT_SHOW", Result: null }, "*");
})
});
</script>
をしかし、私は私のFirefoxのアドオンでメッセージを受信することができないのです。
誰でも手伝いできますか?
2番目のコードブロックで、最初のコードブロックに 'window 'が何であるか(つまり、' var window = ?? what ??; ')と' parent'を知っておく必要があります。 – Makyen
ちょうどFYI:あなたのアドオンで提供されていないHTMLファイル(ウェブベースのソースから提供されているHTMLファイル)を使用している場合は、AMOの配布用に承認されたアドオンを取得することはほとんどありませんあなたのユーザーインターフェイスの。 – Makyen
HTMLファイル(またはボタンがあるもの)を用意してください(例:[mcve])。 – Makyen