从Chrome扩展程序弹出窗口获取价值以在网站文本框中打印

时间:2019-02-17 01:23:25

标签: javascript google-chrome google-chrome-extension

试图在chrome扩展弹出窗口中获取textbox'name_textbox'的值到content_script.js

popup.js

document.addEventListener('DOMContentLoaded', docLoad  , false);

function injectTheScript() {
    textIn=document.getElementById('name_textbox');

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    chrome.tabs.executeScript(tabs[0].id, {file: "content_script.js"});
});
}

function docLoad(){
    document.getElementById('ok_btn').addEventListener('click', injectTheScript);
}

content_script.js

function clickPlanet() {

document.getElementById("register-email").value = textIn;
document.getElementById("register-confirm-email").value = textIn;
} 
clickPlanet();

0 个答案:

没有答案