0
으로 메시지 보내기 각 크롬 탭에 iframe을 동적으로 추가하고 버튼을 추가하는 크롬 확장 프로그램이 있습니다.크롬 확장 프로그램 콘텐츠 메시지에서
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
split_message = msg.action.split("~");
if (split_message[0] == 'load_ifram') {
var id = split_message[1];
var height = '35';
var iframe = document.createElement('iframe');
iframe.src = chrome.extension.getURL('toolbar1.html');
document.documentElement.appendChild(iframe);
}
});
toolbar1.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<input type="text" name="value" id="value" value=""/>
<button id="p_button" style="float:right;line-height:15px;margin-top:-1px;font-family:century gothic;">Click ME</button>
</body>
test.js :
background.js에서 은 내가chrome.tabs.sendMessage(tabs[0].id, {action: "load_ifram~"+id}, function(response) {});
content.js을 content.js에 메시지를 보내
document.addEventListener('DOMContentLoaded', function() {
var p_status = document.querySelector('#p_button');
if(p_status){
p_status.addEventListener('click', p_open);
}
});
content.js에서 나는 background.js에서 ID를 얻고 있습니다. 이 ID는 내 버튼의 값이어야합니다 (ME + id 클릭). 또한이 id 내 단추 클릭 함수 (p_open()) 사용하고 싶습니다. 내가 어떻게 할 수 있니? 도와주세요!! 미리 감사드립니다.