我正在使用Node Webkit创建一个桌面应用程序来在磁盘上创建文件。它正在工作但是当我尝试将成功的消息发送到页面时,它会重新加载页面,将标题栏更改为index.html并删除之前的标题。我做错了什么?
这是代码:
<!DOCTYPE html>
<html lang='en'>
<head>
<title>GPS API Client Builder</title>
<script type="text/javascript">
var nw = require('nw.gui');
//Window Menu
var windowMenu = new nw.Menu({
type: 'menubar'
});
//Help Menu
var helpMenu = new nw.Menu();
// Add to window menu
windowMenu.append(new nw.MenuItem({
label: 'Help',
submenu: helpMenu
}));
//About sub entry
helpMenu.append(new nw.MenuItem({
label: 'About',
click: function() {
alert('I made this!');
}
}));
//Assign window
nw.Window.get().menu = windowMenu;
</script>
</head>
<body>
<h1>GUIApp!</h1>
<!--<script src='script.js' type="text/javascript "></script>-->
<script type="text/javascript ">
var os = require('os');
var os = require('os');
var fs = require('fs');
var content = "";
console.log('estoy en script file');
content += 'This is a test of writing string to a text file' + os.EOL;
content += 'This is a test of writing string to a text file' + os.EOL;
content += 'This is a test of writing string to a text file' + os.EOL;
content += 'This is a test of writing string to a text file' + os.EOL;
console.log('content: ' + content);
//write to file
fs.writeFile('output.txt', content, function(err) {
if (err) {
document.write('Error writing file');
//console.log('error writing');
} else {
document.write('file successfully created');
// console.log('file successfully created');
}
});
</script>
</body>
</html>
答案 0 :(得分:0)
它与write()方法的性质有关。它会覆盖之前的内容。