如何将json文件上传到扩展?

时间:2018-05-04 05:20:08

标签: jquery google-chrome-extension

我正在尝试创建Chrome扩展程序,由于这个特殊原因,我希望我的扩展程序从我的系统中读取文件,但是单击该文件时会打开默认系统文件夹弹出窗口,当我点击该扩展程序时,该扩展程序将关闭。那应该读取数据。

我的代码在这里:

HTML:

    <div class="outer_area">
    <form id="your_form" method="post" enctype="multipart/form-data">
    <input class="input-btn start-button div_one" type="file" id="fileUpload" />
    <button class="input-btn end-button div_two">Convert to sql</button>   
   </div>

popup.js

document.querySelector(".start-button").addEventListener("click", function () {
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        chrome.tabs.sendMessage(tabs[0].id, {action: "start"});
    });
});
document.querySelector(".end-button").addEventListener("click", function () {
    alert('request sent');
   chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        chrome.tabs.sendMessage(tabs[0].id, {action: "end"});
    });
});

content.js: -

chrome.runtime.onMessage.addListener(   
function(request, sender, sendResponse)      
{  
  if(request.action == 'start')
  {
     alert('resquest recived');
     window.open(chrome.extension.getURL("html/popup.html"));

  }

   else if(request.action == 'end')           
   {
            alert('request recived')

    }
   else
   {
    alert('Wrong button placed')
   }


});

0 个答案:

没有答案