节点网络工具包应用程序和页面显示

Node Webkit App and page displayed

本文关键字:显示 应用程序 网络 网络工具 工具包 节点      更新时间:2023-09-26

我正在使用Node Webkit创建一个桌面应用程序,以在磁盘上创建一个文件。 它正在工作,但是当我尝试将成功消息发送到页面时,它会重新加载页面,将标题栏更改为索引.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>

它与 write() 方法的性质有关。 它将超越以前的东西。

[http://www.w3schools.com/jsref/met_doc_write.asp][1]