How can I read/write data from a file?

white_eagle

New Member
I'm writing a simple chrome extension. I need to create the ability to add sites URLs to a list, or read from the list.I use the list to open the sites in the new tabs.I'm looking for a way to have a data file I can write to, and read from. I was thinking on XML. I read there is a problem changing the content of files with Javascript.Is XML the right choice for this kinda thing?I should add that there is no web server, and the app will run locally, so maybe the problem websites are having are not same as this.Before I wrote this question, I tried one thing, and started to feel insecure because it didn't work.
  • I made a XML file called Site.xml:
\[code\]<?xml version="1.0" encoding="utf-8" ?> <Sites> <site> <url> http://www.sulamacademy.com/AddMsgForum.asp?FType=273171&SBLang=0&WSUAccess=0&LocSBID=20375 </url> </site> <site> <url> http://www.wow.co.il </url> </site> <site> <url> http://www.Google.co.il </url> </site>\[/code\]
  • I made this script to read the data from him, and put in on the html file.
\[code\] function LoadXML() { var ajaxObj = new XMLHttpRequest(); ajaxObj.open('GET', 'Sites.xml', false); ajaxObj.send(); var myXML = ajaxObj.responseXML; document.write('<table border="2">'); var prs = myXML.getElementsByTagName("site"); for (i = 0; i < prs.length; i++) { document.write("<tr><td>"); document.write(prs.getElementsByName("url")[0].childNode[0].nodeValue); document.write("</td></tr>"); } document.write("</table"); }\[/code\]
 
Back
Top