Chrome拡張機能からjqueryダイアログボックスを開こうとしています。それについていくつかの投稿がありますが、それらのすべてが私のニーズに関連しているわけではありません。
私は、動作するコードを持っていると主張するこれを見つけました。私は自分の拡張機能でそのメソッドを使用しようとしましたが、成功しませんでした。
バックグラウンドでの私の拡張機能では、次のようにコンテンツスクリプトにメッセージを送信しています。
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: "open_dialog_box"}, function(response) {
});
});
そして、コンテンツスクリプトに、コピーしたコードをほぼそのまま入れました(申し訳ありませんが、念のため、できるだけオリジナルに近づけて、何をいじっているのかを調べたいと思いました。でも):
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse){
if (msg.action == 'open_dialog_box') {
alert("Message recieved!");
var layerNode= document.createElement('div');
layerNode.setAttribute('id','dialog');
layerNode.setAttribute('title','Basic dialog');
var pNode= document.createElement('p');
console.log("pNode created");
pNode.innerHTML = "something";
layerNode.appendChild(pNode);
document.body.appendChild(layerNode);
jQuery("#dialog").dialog({
autoOpen: true,
draggable: true,
resizable: true,
height: 'auto',
width: 500,
zIndex:3999,
modal: false,
open: function(event, ui) {
$(event.target).parent().css('position','fixed');
$(event.target).parent().css('top', '5px');
$(event.target).parent().css('left', '10px');
}
});
これでアラートがポップアップするので、メッセージが到着したことはわかりますが、ダイアログが開いていません。
ここの何が悪いのか教えていただけますか?
編集:
ブロックの要求に従って、ここに私のマニフェストがあります:
{
"name": "Dialog test",
"version": "1.1",
"background":
{
"scripts": ["contextMenus.js"]
},
"permissions": ["tabs", "<all_urls>", "contextMenus"],
"content_scripts" : [
{
"matches" : [ "http://*/*" ],
"js": ["jquery-1.8.3.js", "jquery-ui.js"],
"css": [ "jquery-ui.css" ],
"js": ["openDialog.js"]
}
],
"manifest_version": 2
}