问题陈述: 1.我想根据用户选择阅读本地文件 2.在当前活动页面的文本字段中显示文件内容
清单
{
"manifest_version": 2,
"name": "Click to execute",
"description": "Testing read file",
"version": "1.0",
"icons": {
"48": "icon.png"
},
"permissions": [
"tabs","all_urls","activeTab"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"js": ["content.js"],
"run_at": "document_end"
}
]
}
popup.js
function openfile1(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
console.log(reader.result.substring(0, 200));
displayintext(text);
// alert("File Content----"+reader.result.substring(0, 500));
};
reader.readAsText(input.files[0]);
};
function displayintext(finalvalue)
{
var f1 = finalvalue;
alert("finalvalue "+ f1);
//chrome.tabs.executeScript(null, {code: "var Sbonus= getTextInControl("AH_5fOTHER_5fBONUS_5fGRAND_5fTOTAL"); alert(Sbonus);"});
}
document.getElementById('opentest').addEventListener('change', openfile1, false);
Content.js
/*
var Sbonus= getTextInControl("AH_5fOTHER_5fBONUS_5fGRAND_5fTOTAL");
var SpliAmt = Sbonus /4;
console.log(Sbonus);
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f1",SpliAmt);
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f2",SpliAmt);
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f3",SpliAmt);
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f4",SpliAmt);
console.log(SpliAmt);
我对chrome扩展开发完全陌生。我无法让代码工作。扩展程序能够读取文件并在警报上显示内容。
现在,我想执行内容脚本以从content.js
中的当前活动页面读取文本字段的值,并将其中一个文本字段中的前一个文件内容的值粘贴。< / p>
非常感谢任何帮助。