0
我有下面的代碼在Chrome工作但不FF或IE瀏覽器。腳本作品在Chrome,但不是在IE或者FF
的代碼允許用戶選擇一個文本文件,並重新讀取每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">
\t \t
\t \t
\t var currentIntervalId = undefined;
\t \t var startOrRestart = function(that) {
\t \t if (currentIntervalId !== undefined) clearInterval(currentIntervalId);
\t \t readText(that); // For executing immediately
\t \t currentIntervalId = setInterval(function() { readText(that); }, 10000);
\t \t };
\t \t
\t \t function readText(that){
\t \t \t if(that.files && that.files[0]){
\t \t \t //alert("hello");
\t \t \t \t var reader = new FileReader();
\t \t \t \t reader.onload = function (e) {
\t \t \t \t \t var contents = e.target.result;//.replace("\r\n","<br/>");
\t \t \t \t \t contents = contents.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
\t \t \t \t \t document.getElementById('board').innerHTML= contents;
\t \t \t \t };//end onload()
\t \t \t \t reader.readAsText(that.files[0]);
\t \t \t }//end if html5 filelist support
\t \t }
\t \t
</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>
有人可以幫得到這個在其他瀏覽器?
在此先感謝。