简体   繁体   中英

Javascript: Load listbox items from a text file

I'm making a google extension that injects a lisbox into html page. I need the items for this listbox to be taken from a local textfile (or any other editable source on local PC).

This is what I have right now:

ItemCode.insertAdjacentHTML(
    'afterend', 
    '<select id="name" name="name">
       <option value="">Your keyword...</option>
       <option value="Elvis">Elvis</option>
       <option value="Frank">Frank</option>
       <option value="Jim">Jim</option>
     </select>'
);

I want this values to be taken from a file keywords.txt which in on the Windows Desktop Location and contains the following:

Elvis
Frank
Jim

Is it possible please? Thanks.

Here is the code:

 // I have no text file, so I will put static content in a string. But bellow is how to get a text file. // Get text file: // // var client = new XMLHttpRequest(); // client.open('GET', '/foo.txt'); // client.onreadystatechange = function() { // var filetext = client.responseText; // } // client.send(); var fileText = "Elvis\\nFrank\\nJim"; var people = fileText.split("\\n"); var htmlString = '<select id="name" name="name"><option value="">Your keyword...</option>'; for (person in people) { htmlString = htmlString + '<option value="'+people[person]+'">'+people[person]+'</option>'; } htmlString = htmlString + '</select>'; document.write(htmlString); 

it is not possible, i searched the internet . i don't think this code released. also the code above doesn't work because no matter what you do , the list in the html page will consist of file.txt. thats all you get from this code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM