2017-05-04 62 views
-1

我想讓這寫到服務器上的本地文件,我遇到了這樣的問題。我得到它來寫一個文件,然後在瀏覽器中閱讀,但我不能把它的鏈接,以便其他人可以運行彈出橫幅輸入信息。這裏是我正在使用的JavaScript。我知道使用字幕不是最好的,但這是必需的。此外,這隻需要在本地網絡上工作,而不是面向互聯網。這將在服務器上運行,並且服務器上的文件鏈接是提供給其他人的。而且更重要的是,頁面將從同一文件夾中運行。對於那個很抱歉。感謝您的幫助。Javascript寫一個文件

已解決我在這裏找到了我的問題的答案。 https://github.com/jimmywarting/StreamSaver.js

   ---------------Test.js file----------- 
function openWin() { 
var myWindow = window.open("", "MsgWindow", "width=2000,height=200,location=no,notoolbar=no,menubar=no,scrollbars=yes,left=0,top=950"); 
var text = document.getElementById('notebox'); 
var image1 = document.getElementById('image1'); 
var image2 = document.getElementById('image2'); 
var imlink = document.getElementById('imlink'); 
var background = document.getElementById('background'); 
var fontsize = document.getElementById('fontsize'); 
var fontcolor = document.getElementById('fontcolor'); 
var fonttype = document.getElementById('fonttype'); 
var fontspeed = document.getElementById('fontspeed'); 
    myWindow.document.write("<marquee behavior='scroll' direction='left' scrollamount='" + fontspeed.value + "' BGCOLOR='" + background.value + "'><h1 style='font-size:" + fontsize.value + "px;color:" + fontcolor.value + ";font-family:" + fonttype.value + ";'><img src='" + image1.value + "' style='width:100px;height:100px;' > " + text.value + " <img src='" + image2.value + "' style='width:100px;height:100px;' ></h1></marquee>"); 
    myWindow.document.close() 
} 
function SaveDatFileBro(localstorage) { 
    localstorage.root.getFile("Banner.html", {create: true}); 
} 


--------------------------------Banner.html--------------------------------- 
<!DOCTYPE html> 
<html> 
<head> 
<title> 
</title> 
</head> 
<body> 

<script src="Test.js"></script> 

<table style="margin:0px auto 0px auto"> 
    <tr> 
     <td><input type="button" value=" Open Banner" onclick="openWin();SaveDatFileBro()"/></td> 
    <td><input type="text" id="notebox" value="Enter Notification" size="120"/></td> 
    </tr> 
    <tr> 
     <td><input type="button" value=" Save Banner" onclick="SaveDatFileBro()"/></td> 
     <td>Font Color:<input type="text" id="fontcolor" value="Red"/> Font Type:<input type="text" id="fonttype" value="Times New Roman"/> Font Size:<input type="text" id="fontsize" value="130" /> Scroll Speed:<input type="text" id="fontspeed" value="25" /></td> 
    </tr> 
     <tr> 
     <td></td> 
     <td>Background Color:<input type="text" id="background" value="White" /> Leading Image:<input type="text" id="image1" value="https://vignette2.wikia.nocookie.net/uncyclopedia/images/4/44/White_square.png/revision/latest/scale-to-width-down/200?cb=20061003200043" /> Trailing Image:<input type="text" id="image2" value="https://vignette2.wikia.nocookie.net/uncyclopedia/images/4/44/White_square.png/revision/latest/scale-to-width-down/200?cb=20061003200043" /></td> 
    </tr> 
</table> 


</body> 
</html> 
+0

如果要將數據存儲在服務器上,則需要在服務器上運行代碼以保存該文件。 – epascarello

+0

它將在服務器上運行,但目前無法在運行時保存到本地計算機。 – Sean

回答

-1

這是不可能的。您的瀏覽器完全無法訪問服務器上的文件系統。

如果要寫入服務器的文件系統,需要一個服務器端進程來偵聽通過HTTP從瀏覽器提交給它的數據。