Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read and display file in a chrome extension

I want to read and display the contents of file in a chrome extension (The file is already inside the extension directory).How do it?Whether I can use HTML5 to read it?

  var elema3 = document.body.getElementsByClassName("slicefooter");
  elema3[0].innerHTML='Shanmuga Subramanian';

  var a1=chrome.extension.getURL('script1.txt');
  var reader = new FileReader();
  reader.readAsText(a1);
like image 400
Shan Avatar asked Dec 12 '12 03:12

Shan


People also ask

Can Chrome Extensions read files?

Often, it is desirable for a Chrome extension to be bundled with files that need to be read. These files may contain data or configuration information to help the extension function. This short guide will show you how you can set up your Chrome extension to read files.

How do I display my Chrome extensions?

On your computer, open Chrome . At the top right, click Extensions .

How do I add a read aloud extension in Chrome?

Search Google → Chrome Web Store → Read Aloud or visit this link: Chrome Extension Reader 2. Select “Add to Chrome” button next to the “Read Aloud” option. 3. A pop-up box will appear - select the “Add extension” button.

What is the Chrome extension that reads text?

'Text Reader' is a chrome extension that Reads for you, texts you select from websites you visit. It also have an editing window where you can type your own words/sentences to be read out loud or even upload a text document to the window or use your mic to type.


1 Answers

Use XMLHttpRequest.

Example:

var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('script1.txt'), true);
xhr.onreadystatechange = function()
{
    if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200)
    {
        //... The content has been read in xhr.responseText
    }
};
xhr.send();
like image 189
方 觉 Avatar answered Oct 21 '22 22:10

方 觉