我有一个小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(); " />
这是为什么?我该如何解决?
答案 0 :(得分:0)
所以对于我想要的,答案很简单,不需要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" >