Chrome 확장 프로그램에서 jquery 대화 상자를 열려고합니다. 그것에 관한 여러 게시물이 있습니다. 모든 게시물이 내 필요와 관련이있는 것은 아닙니다.크롬 확장 : 메시지 이벤트가 발생하여 콘텐츠 스크립트에서 jquery UI 대화 상자 열기
작동 코드가 있다고 주장하는 this one을 발견했습니다. 내 확장 기능에서 그 방법을 사용하려고 시도했지만 성공하지 못했습니다. 다음과 같이 배경에 내 확장에
내가 콘텐츠 스크립트에 메시지를 통해 보내고있다 :chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: "open_dialog_box"}, function(response) {
});
});
및 컨텐츠 스크립트에서 I는 나는 거의 복사 한 코드를 넣었습니다 (즉 죄송합니다,하지만 난 그래도 엉망으로하고 있는지 확인하려면 가능한 한 원본과 더 가까운되고 싶어 바로 아래로 못을 박기 위해) : 이제
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
}
감사합니다. 코드에서 메시지 사용을 제거했지만 여전히 아무것도 사용하지 않았습니다. 콘솔 로그는 오류에 대해 불평하지 않습니다. 또한, 내 매니페스트를 추가했습니다. – Subway
아아, 나는 웹 페이지 콘솔 로그를 봐야했다. 맞아, 콘솔 말한다 : '정의되지 않은'이벤트 처리기에서 오류 : jQuery 정의되지 않았습니다. ReferenceError : jQuery 정의되지 않습니다. 하지만 편집 된 질문에서 볼 수있는 것처럼 jquery를 매니페스트에 포함 시켰습니다. – Subway
예. 언급 된 모든 파일은 기본 폴더에 있습니다. 그러나 여기에 이상한 점이 있습니다 : manifest를 "css": [ "jquery-ui.css"], \t \t \t "js": [ "jquery-1.8.3.js" "jquery-ui.js", "openDialog.js "]', jquery-ui.js에 대해로드 할 수 없습니다. utf-8로 인코딩되지 않았습니다. 현재 문제와 관련이 있는지는 모르겠지만 이제 첨부 된 매니페스트가로드되었습니다. – Subway