Read csv file with javascriptCreate GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

What is the largest number of identical satellites launched together?

Conditional probability - sum of dice is even given that at least one is a five

German characters on US-International keyboard layout

Tikz draw contour without some edges, and fill

On what legal basis did the UK remove the 'European Union' from its passport?

In books, how many dragons are there in present time?

Is there any good reason to write "it is easy to see"?

Ito`s Lemma problem

How exactly does artificial gravity work?

Ex-manager wants to stay in touch, I don't want to

What to do if SUS scores contradict qualitative feedback?

Unbounded Fredholms operators

If current results hold, Man City would win PL title

How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?

Jumping frame contents with beamer and pgfplots

Stuck filament in the extruder of Infitary M508

Anabelian geometry ~ higher category theory

What kind of SATA connector is this?

LWC1513: @salesforce/resourceUrl modules only support default imports

Why was Endgame Thanos so different than Infinity War Thanos?

Chain link speeds

CPLD based Pierce oscillator

Automatically anti-predictably assemble an alliterative aria

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?



Read csv file with javascript


Create GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Currently im using this code to view content of a csv in a webbrowser with javascript. But this only works in firefox as other browser dont allow you to grab content from an iframe. I need to convert my csv to a txt if i want to use this method, and would like to keep csv instead of txt.



Do any of you know how I can make this work without the Iframe part and txt part so I can use it in different browser? Thanks!



<iframe id="frmFile" src="content/assets/output.txt" onload="LoadFile();" style="display: none;"></iframe>

<script>function LoadFile()
var oFrame = document.getElementById("frmFile");
var strRawContents = oFrame.contentWindow.document.body.childNodes[0].innerHTML;

while (strRawContents.indexOf("r") >= 0)
strRawContents = strRawContents.replace("r", "");
var arrLines = strRawContents.split("n");
var alltext = "";

if(arrLines[12].split(";")[8] == "0")
for (var i = 1; i < arrLines.length; i++)

alltext += "<tr>";
var prop = arrLines[i].split(";");
for (var j = 0; j < 11; j++)
alltext += "<td>" + prop[j] + "</td>";

alltext += "</tr>";
document.close();

document.getElementById("message").innerHTML = alltext;

</script>









share|improve this question




























    0















    Currently im using this code to view content of a csv in a webbrowser with javascript. But this only works in firefox as other browser dont allow you to grab content from an iframe. I need to convert my csv to a txt if i want to use this method, and would like to keep csv instead of txt.



    Do any of you know how I can make this work without the Iframe part and txt part so I can use it in different browser? Thanks!



    <iframe id="frmFile" src="content/assets/output.txt" onload="LoadFile();" style="display: none;"></iframe>

    <script>function LoadFile()
    var oFrame = document.getElementById("frmFile");
    var strRawContents = oFrame.contentWindow.document.body.childNodes[0].innerHTML;

    while (strRawContents.indexOf("r") >= 0)
    strRawContents = strRawContents.replace("r", "");
    var arrLines = strRawContents.split("n");
    var alltext = "";

    if(arrLines[12].split(";")[8] == "0")
    for (var i = 1; i < arrLines.length; i++)

    alltext += "<tr>";
    var prop = arrLines[i].split(";");
    for (var j = 0; j < 11; j++)
    alltext += "<td>" + prop[j] + "</td>";

    alltext += "</tr>";
    document.close();

    document.getElementById("message").innerHTML = alltext;

    </script>









    share|improve this question
























      0












      0








      0








      Currently im using this code to view content of a csv in a webbrowser with javascript. But this only works in firefox as other browser dont allow you to grab content from an iframe. I need to convert my csv to a txt if i want to use this method, and would like to keep csv instead of txt.



      Do any of you know how I can make this work without the Iframe part and txt part so I can use it in different browser? Thanks!



      <iframe id="frmFile" src="content/assets/output.txt" onload="LoadFile();" style="display: none;"></iframe>

      <script>function LoadFile()
      var oFrame = document.getElementById("frmFile");
      var strRawContents = oFrame.contentWindow.document.body.childNodes[0].innerHTML;

      while (strRawContents.indexOf("r") >= 0)
      strRawContents = strRawContents.replace("r", "");
      var arrLines = strRawContents.split("n");
      var alltext = "";

      if(arrLines[12].split(";")[8] == "0")
      for (var i = 1; i < arrLines.length; i++)

      alltext += "<tr>";
      var prop = arrLines[i].split(";");
      for (var j = 0; j < 11; j++)
      alltext += "<td>" + prop[j] + "</td>";

      alltext += "</tr>";
      document.close();

      document.getElementById("message").innerHTML = alltext;

      </script>









      share|improve this question














      Currently im using this code to view content of a csv in a webbrowser with javascript. But this only works in firefox as other browser dont allow you to grab content from an iframe. I need to convert my csv to a txt if i want to use this method, and would like to keep csv instead of txt.



      Do any of you know how I can make this work without the Iframe part and txt part so I can use it in different browser? Thanks!



      <iframe id="frmFile" src="content/assets/output.txt" onload="LoadFile();" style="display: none;"></iframe>

      <script>function LoadFile()
      var oFrame = document.getElementById("frmFile");
      var strRawContents = oFrame.contentWindow.document.body.childNodes[0].innerHTML;

      while (strRawContents.indexOf("r") >= 0)
      strRawContents = strRawContents.replace("r", "");
      var arrLines = strRawContents.split("n");
      var alltext = "";

      if(arrLines[12].split(";")[8] == "0")
      for (var i = 1; i < arrLines.length; i++)

      alltext += "<tr>";
      var prop = arrLines[i].split(";");
      for (var j = 0; j < 11; j++)
      alltext += "<td>" + prop[j] + "</td>";

      alltext += "</tr>";
      document.close();

      document.getElementById("message").innerHTML = alltext;

      </script>






      javascript csv iframe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 27 '17 at 21:15









      JeroenJeroen

      184




      184






















          1 Answer
          1






          active

          oldest

          votes


















          1














          I would suggest Ajax get of the file -> that way you can get the text content.



          <!-- no iframe -->

          <script>
          var url = "http://www.example.com/file.txt";
          var txtFile = new XMLHttpRequest();
          txtFile.open("GET",url,true);
          txtFile.send();

          txtFile.onreadystatechange = function()
          if (txtFile.readyState== 4 && txtFile.status == 200)

          var strRawContents = jsonFile.responseText;


          </script>





          share|improve this answer

























          • Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

            – Jeroen
            Jun 27 '17 at 21:30












          • Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

            – WuDo
            Jun 27 '17 at 21:38











          • Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

            – Jeroen
            Jun 28 '17 at 14:06











          • C'mon man at least sense check your code before posting. Half of the conditional statement is missing

            – JordanGW
            Mar 23 at 10:19











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44790026%2fread-csv-file-with-javascript%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I would suggest Ajax get of the file -> that way you can get the text content.



          <!-- no iframe -->

          <script>
          var url = "http://www.example.com/file.txt";
          var txtFile = new XMLHttpRequest();
          txtFile.open("GET",url,true);
          txtFile.send();

          txtFile.onreadystatechange = function()
          if (txtFile.readyState== 4 && txtFile.status == 200)

          var strRawContents = jsonFile.responseText;


          </script>





          share|improve this answer

























          • Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

            – Jeroen
            Jun 27 '17 at 21:30












          • Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

            – WuDo
            Jun 27 '17 at 21:38











          • Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

            – Jeroen
            Jun 28 '17 at 14:06











          • C'mon man at least sense check your code before posting. Half of the conditional statement is missing

            – JordanGW
            Mar 23 at 10:19















          1














          I would suggest Ajax get of the file -> that way you can get the text content.



          <!-- no iframe -->

          <script>
          var url = "http://www.example.com/file.txt";
          var txtFile = new XMLHttpRequest();
          txtFile.open("GET",url,true);
          txtFile.send();

          txtFile.onreadystatechange = function()
          if (txtFile.readyState== 4 && txtFile.status == 200)

          var strRawContents = jsonFile.responseText;


          </script>





          share|improve this answer

























          • Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

            – Jeroen
            Jun 27 '17 at 21:30












          • Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

            – WuDo
            Jun 27 '17 at 21:38











          • Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

            – Jeroen
            Jun 28 '17 at 14:06











          • C'mon man at least sense check your code before posting. Half of the conditional statement is missing

            – JordanGW
            Mar 23 at 10:19













          1












          1








          1







          I would suggest Ajax get of the file -> that way you can get the text content.



          <!-- no iframe -->

          <script>
          var url = "http://www.example.com/file.txt";
          var txtFile = new XMLHttpRequest();
          txtFile.open("GET",url,true);
          txtFile.send();

          txtFile.onreadystatechange = function()
          if (txtFile.readyState== 4 && txtFile.status == 200)

          var strRawContents = jsonFile.responseText;


          </script>





          share|improve this answer















          I would suggest Ajax get of the file -> that way you can get the text content.



          <!-- no iframe -->

          <script>
          var url = "http://www.example.com/file.txt";
          var txtFile = new XMLHttpRequest();
          txtFile.open("GET",url,true);
          txtFile.send();

          txtFile.onreadystatechange = function()
          if (txtFile.readyState== 4 && txtFile.status == 200)

          var strRawContents = jsonFile.responseText;


          </script>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 23 at 13:06









          JordanGW

          6419




          6419










          answered Jun 27 '17 at 21:23









          WuDoWuDo

          1277




          1277












          • Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

            – Jeroen
            Jun 27 '17 at 21:30












          • Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

            – WuDo
            Jun 27 '17 at 21:38











          • Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

            – Jeroen
            Jun 28 '17 at 14:06











          • C'mon man at least sense check your code before posting. Half of the conditional statement is missing

            – JordanGW
            Mar 23 at 10:19

















          • Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

            – Jeroen
            Jun 27 '17 at 21:30












          • Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

            – WuDo
            Jun 27 '17 at 21:38











          • Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

            – Jeroen
            Jun 28 '17 at 14:06











          • C'mon man at least sense check your code before posting. Half of the conditional statement is missing

            – JordanGW
            Mar 23 at 10:19
















          Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

          – Jeroen
          Jun 27 '17 at 21:30






          Like this?: pastebin.com/raw/0xpCmgRE That gives this error: Uncaught ReferenceError: LoadFile is not defined at HTMLIFrameElement.onload

          – Jeroen
          Jun 27 '17 at 21:30














          Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

          – WuDo
          Jun 27 '17 at 21:38





          Edited the response. It's done completely without iframe and response text is the text of file (now named the same way as you have).

          – WuDo
          Jun 27 '17 at 21:38













          Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

          – Jeroen
          Jun 28 '17 at 14:06





          Using your code it says: Uncaught SyntaxError: Unexpected token var Using this (pastebin.com/raw/Zw2q8JtZ) code I get: MLHttpRequest cannot load file:///C:/Users/Jay/test/etc/output.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

          – Jeroen
          Jun 28 '17 at 14:06













          C'mon man at least sense check your code before posting. Half of the conditional statement is missing

          – JordanGW
          Mar 23 at 10:19





          C'mon man at least sense check your code before posting. Half of the conditional statement is missing

          – JordanGW
          Mar 23 at 10:19



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44790026%2fread-csv-file-with-javascript%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

          밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

          1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴