0

I developed a Javascript program which works fine in a Windows 8 PC but not in Windows 7.

This program has a button that allows user to choose a file and display the content in a textarea.

The webpage is tested in the following versions:

On Windows 7 - Chrome 20.0.1132.47 m and IE7 On Windows 8 - Chrome on 20.0.1132.47 m and IE9

Could it be due to the different Windows versions? Anyway to overcome it by adjusting the machine configuration or program code? I'm willing to attach the code if it's due to the latter.

Thanks.

  • 1
    Yes code would be helpful. There are many quirks with cross browser compatibility. – Raekye Jan 21 '13 at 07:35
  • I tried to attach my code by clicking on "Post Answer" but it doesn't allow me as my reputation is less than 10. Is there other ways or have to wait for 8 more hours before posting it? – user1721994 Jan 21 '13 at 08:58
  • I kind of doubt that it will have anything to do with OS versions. It will probably have more to do with the browser version. – starbeamrainbowlabs Jan 21 '13 at 09:46
  • @user172994 You can click on "edit" under your question – Raekye Jan 21 '13 at 18:37

1 Answers1

0

This is a program to decrypt some text from a file. A button allows the user to select a file from an Open Dialog Box. Upon selection, the contents will be displayed in the input textarea.

Please ignore the modules "readByLine" and "readKeyword" below as there are some problems.

Not sure if HTML5 supports in Chrome 20.0.1132.47 m and IE7.

Attaching the code as below:

<html>
<head>
<script type="text/javascript">

//Select a Cipher file from Open Dialog Box
function readCipherFile()
{           
    if (!window.FileReader)
      document.getElementById("cipher").innerHTML = "<p>This browser doesn\'t support File API</p>";
    else
    {
        // Input handler for cipher text
        document.getElementById("cipherfile").onchange = function() { 
                                                    readFileAsText(this.files[0]);
                                                    };
    }
}

//Read content as text and display in Input textarea
function readFileAsText(file)
{
    var reader = new FileReader();

    reader.readAsText(file);
    reader.onload = function(event) {
      document.getElementById("cipher").innerHTML = event.target.result;
    };

    reader.onerror = function() {
      document.getElementById("cipher").innerHTML = 'Unable to read ' + file.fileName;
    };
}

//Select a Keyword file from Open Dialog Box
function readKeyword()
{
    if (!window.FileReader)
      document.getElementById("keyword").innerHTML = "<p>This browser doesn\'t support File API</p>";
    else
    {
        // Input handler for keyword
        document.getElementById("keyfile").onchange = function() { 
                                                    readByLine(this.files[0]);
                                                    };
    }
}

//Read and display one keyword at a time
function readByLine(file)
{
    var reader = new FileReader();
    var arr = "";

    console.log("test" + arr);
    console.log(file);
    reader.onload = function(event) {
      arr = event.target.result;
    };

    reader.readAsText(file);        

    for(i=0; i<arr.length; i++)
    {
        arr = arr.split("\n");
        document.getElementById("keyword").value = arr;
    }

    //display the next keyword when button is clicked
    var keyButton = document.getElementById("keyfile");
    keyButton.addEventListener("click", readByLine, false);
}

</script>

</head>
<body>
<center>
<h2>Vigenere Cipher</h2>
<br>
    <form name="form1">
      <table>
         <tr>
           <td>
             Input:
           </td>
           <td>
              <textarea name=input id="cipher" rows=10 cols=60 wrap=virtual></textarea>
           </td>
         </tr>
     <tr>
    <td></td>
    <td align="center">
        <input type=file id="cipherfile" onClick="readCipherFile(this)" />
    </td>
     </tr>
     <tr height="20px"></tr>
    <tr>
      <td>
        Key:
      </td>
      <td>
        <textarea name=key id="keyword" rows=2 cols=60 wrap=virtual></textarea>
      </td>
      <tr>
        <td></td>
        <td align="center">
            <input type=file id="keyfile" onClick="readKeyword()" />
        </td>
      </tr>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
    <tr>
      <td></td>
      <td>
        <input type=button value="Decrypt" onClick="decode()" style="margin-left: 135px">
      </td>
    </tr>
      <td>
        Output:
      </td>
      <td>
        <textarea id="output" rows=10 cols=60 wrap=virtual></textarea>
      </td>
    </table>
</form>
</center>
</body>
<html>