读取本地文件的Javascript适用于Windows,但不适用于Linux



我有一个小的Javascript,它应该读取本地文本文件的内容并将其显示在浏览器屏幕上。它适用于具有当前Firefox的Windows 7,但不适用于具有当前Firefox或chrome的fedroa 20。这是代码:

<h1>View file content</h1>
<script>
function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
}
function read_status()
{
    readTextFile('file:///tmp/status.txt');
}
</script>
<input id="clickMe" type="button" value="Current status" onclick="read_status(); " />

这是为什么呢?我该如何解决它?

所以对于我想要的,答案非常简单,不需要java脚本,只需要普通的html:

<h1>Status </h1>
<meta http-equiv="refresh" content="1" > 
<object width="100%" height="100%" type="text/plain" data="/tmp/status.txt" border="0" >

最新更新