简体   繁体   English

脚本在Chrome中有效,但在IE或FF中不起作用

[英]Script works in Chrome but not in IE or FF

I have the following code that works in chrome however does not work in FF or IE. 我有以下代码可在chrome中使用,但是在FF或IE中无法使用。

The code allows a user to select a text file and re-reads the contents every 10 seconds and updates the PRE tag with the contents of the text file. 该代码允许用户选择一个文本文件,并每10秒重新读取一次内容,并使用文本文件的内容更新PRE标签。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Read text file every 10 seconds</title> <script type="text/javascript"> var currentIntervalId = undefined; var startOrRestart = function(that) { if (currentIntervalId !== undefined) clearInterval(currentIntervalId); readText(that); // For executing immediately currentIntervalId = setInterval(function() { readText(that); }, 10000); }; function readText(that){ if(that.files && that.files[0]){ //alert("hello"); var reader = new FileReader(); reader.onload = function (e) { var contents = e.target.result;//.replace("\\r\\n","<br/>"); contents = contents.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); document.getElementById('board').innerHTML= contents; };//end onload() reader.readAsText(that.files[0]); }//end if html5 filelist support } </script> </head> <body> <input type="file" onchange='startOrRestart(this)' /> <hr /> <pre id="board" contenteditable = "true"> This is where the text from the chosen text file will be loaded. </pre> </body> </html> 

Can someone help get this to work in other browsers? 有人可以帮助它在其他浏览器中工作吗?

Thanks in advance. 提前致谢。

When a file is selected the input has a snapshot of the contents at that point. 选择文件后,输入将具有此时内容的快照。 Local changes on disk don't update the snapshot. 磁盘上的本地更改不会更新快照。

Chrome's implementation appears to break the spec so an example will work only in Chrome. Chrome的实现似乎违反了规范,因此仅在Chrome中可以使用示例。

You can see another question with explanation here 您可以在此处看到另一个带有说明的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM