首页 技术 正文
技术 2022年11月13日
0 收藏 986 点赞 4,944 浏览 16271 个字

<!–
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:微软雅黑;
panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
{font-family:华文隶书;
panose-1:2 1 8 0 4 1 1 1 1 1;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:华文楷体;
panose-1:2 1 6 0 4 1 1 1 1 1;}
@font-face
{font-family:”\@宋体”;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:”\@微软雅黑”;
panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
{font-family:”\@华文楷体”;
panose-1:2 1 6 0 4 1 1 1 1 1;}
@font-face
{font-family:”\@华文隶书”;
panose-1:2 1 8 0 4 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}

h2
{mso-style-link:”标题 2 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-align:center;
text-indent:10.0pt;
line-height:115%;
background:#DBE5F1;
border:none;
padding:0cm;
font-size:14.0pt;
font-family:”Calibri”,”sans-serif”;
text-transform:uppercase;
letter-spacing:.75pt;
font-weight:normal;}
h3
{mso-style-link:”标题 3 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
border:none;
padding:0cm;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
color:#243F60;
letter-spacing:.75pt;
font-weight:normal;}
h4
{mso-style-name:”标题 4\,代码”;
mso-style-link:”标题 4 Char\,代码 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:24.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;
font-weight:normal;}
h5
{mso-style-link:”标题 5 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
border:none;
padding:0cm;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
color:#244061;
letter-spacing:.5pt;
font-weight:bold;}
h6
{mso-style-link:”标题 6 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
border:none;
padding:0cm;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
color:#365F91;
text-transform:uppercase;
letter-spacing:.5pt;
font-weight:normal;}
p.MsoHeading7, li.MsoHeading7, div.MsoHeading7
{mso-style-link:”标题 7 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
color:#365F91;
text-transform:uppercase;
letter-spacing:.5pt;}
p.MsoHeading8, li.MsoHeading8, div.MsoHeading8
{mso-style-link:”标题 8 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
font-size:9.0pt;
font-family:”Calibri”,”sans-serif”;
text-transform:uppercase;
letter-spacing:.5pt;}
p.MsoHeading9, li.MsoHeading9, div.MsoHeading9
{mso-style-link:”标题 9 Char”;
margin-top:15.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
font-size:9.0pt;
font-family:”Calibri”,”sans-serif”;
text-transform:uppercase;
letter-spacing:.5pt;
font-style:italic;}
p.MsoToc1, li.MsoToc1, div.MsoToc1
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoToc2, li.MsoToc2, div.MsoToc2
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:21.0pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoToc3, li.MsoToc3, div.MsoToc3
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:42.0pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoHeader, li.MsoHeader, div.MsoHeader
{mso-style-link:”页眉 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-align:center;
text-indent:10.0pt;
line-height:115%;
layout-grid-mode:char;
border:none;
padding:0cm;
font-size:9.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
{mso-style-link:”页脚 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
layout-grid-mode:char;
font-size:9.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoCaption, li.MsoCaption, div.MsoCaption
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:8.0pt;
font-family:”Calibri”,”sans-serif”;
color:#365F91;
font-weight:bold;}
p.MsoTitle, li.MsoTitle, div.MsoTitle
{mso-style-link:”标题 Char”;
margin-top:36.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:26.0pt;
font-family:”Calibri”,”sans-serif”;
color:#4F81BD;
text-transform:uppercase;
letter-spacing:.5pt;}
p.MsoSubtitle, li.MsoSubtitle, div.MsoSubtitle
{mso-style-link:”副标题 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:50.0pt;
margin-left:0cm;
text-indent:10.0pt;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;
color:#595959;
text-transform:uppercase;
letter-spacing:.5pt;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
em
{color:#243F60;
text-transform:uppercase;
letter-spacing:.25pt;
font-style:normal;}
p.MsoDocumentMap, li.MsoDocumentMap, div.MsoDocumentMap
{mso-style-link:”文档结构图 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:9.0pt;
font-family:宋体;}
p
{margin-right:0cm;
margin-left:0cm;
font-size:12.0pt;
font-family:宋体;}
code
{font-family:宋体;}
pre
{mso-style-link:”HTML 预设格式 Char”;
margin:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
font-size:12.0pt;
font-family:宋体;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-link:”批注框文本 Char”;
margin:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
font-size:9.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
{mso-style-link:”无间隔 Char”;
margin:0cm;
margin-bottom:.0001pt;
text-indent:10.0pt;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:36.0pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
{margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
{margin-top:0cm;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:36.0pt;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
p.MsoQuote, li.MsoQuote, div.MsoQuote
{mso-style-link:”引用 Char”;
margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
text-indent:10.0pt;
line-height:115%;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;
font-style:italic;}
p.MsoIntenseQuote, li.MsoIntenseQuote, div.MsoIntenseQuote
{mso-style-link:”明显引用 Char”;
margin-top:10.0pt;
margin-right:57.6pt;
margin-bottom:0cm;
margin-left:64.8pt;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:10.0pt;
line-height:115%;
border:none;
padding:0cm;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;
color:#4F81BD;
font-style:italic;}
span.MsoSubtleEmphasis
{color:#243F60;
font-style:italic;}
span.MsoIntenseEmphasis
{color:#243F60;
text-transform:uppercase;
letter-spacing:.5pt;
font-weight:bold;}
span.MsoSubtleReference
{color:#4F81BD;
font-weight:bold;}
span.MsoIntenseReference
{color:#4F81BD;
text-transform:uppercase;
font-weight:bold;
font-style:italic;}
span.MsoBookTitle
{letter-spacing:.45pt;
font-weight:bold;
font-style:italic;}
p.MsoTocHeading, li.MsoTocHeading, div.MsoTocHeading
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:0cm;
margin-left:0cm;
margin-bottom:.0001pt;
text-align:center;
text-indent:10.0pt;
line-height:115%;
background:#4F81BD;
border:none;
padding:0cm;
font-size:24.0pt;
font-family:”Calibri”,”sans-serif”;
color:white;
text-transform:uppercase;
letter-spacing:.75pt;
font-weight:bold;}
span.Char
{mso-style-name:”页眉 Char”;
mso-style-link:页眉;}
span.Char0
{mso-style-name:”页脚 Char”;
mso-style-link:页脚;}
span.1Char
{mso-style-name:”标题 1 Char”;
mso-style-link:”标题 1″;
font-family:”微软雅黑”,”sans-serif”;
color:white;
text-transform:uppercase;
letter-spacing:.75pt;
background:#4F81BD;
font-weight:bold;}
span.Char1
{mso-style-name:”文档结构图 Char”;
mso-style-link:文档结构图;
font-family:宋体;}
span.2Char
{mso-style-name:”标题 2 Char”;
mso-style-link:”标题 2″;
font-family:华文隶书;
text-transform:uppercase;
letter-spacing:.75pt;
background:#DBE5F1;}
span.3Char
{mso-style-name:”标题 3 Char”;
mso-style-link:”标题 3″;
color:#243F60;
letter-spacing:.75pt;}
span.4Char
{mso-style-name:”标题 4 Char\,代码 Char”;
mso-style-link:”标题 4\,代码”;}
span.5Char
{mso-style-name:”标题 5 Char”;
mso-style-link:”标题 5″;
color:#244061;
letter-spacing:.5pt;
font-weight:bold;}
span.6Char
{mso-style-name:”标题 6 Char”;
mso-style-link:”标题 6″;
color:#365F91;
text-transform:uppercase;
letter-spacing:.5pt;}
span.7Char
{mso-style-name:”标题 7 Char”;
mso-style-link:”标题 7″;
color:#365F91;
text-transform:uppercase;
letter-spacing:.5pt;}
span.8Char
{mso-style-name:”标题 8 Char”;
mso-style-link:”标题 8″;
text-transform:uppercase;
letter-spacing:.5pt;}
span.9Char
{mso-style-name:”标题 9 Char”;
mso-style-link:”标题 9″;
text-transform:uppercase;
letter-spacing:.5pt;
font-style:italic;}
span.Char2
{mso-style-name:”标题 Char”;
mso-style-link:标题;
color:#4F81BD;
text-transform:uppercase;
letter-spacing:.5pt;}
span.Char3
{mso-style-name:”副标题 Char”;
mso-style-link:副标题;
color:#595959;
text-transform:uppercase;
letter-spacing:.5pt;}
span.Char4
{mso-style-name:”无间隔 Char”;
mso-style-link:无间隔;}
span.Char5
{mso-style-name:”引用 Char”;
mso-style-link:引用;
font-style:italic;}
span.Char6
{mso-style-name:”明显引用 Char”;
mso-style-link:明显引用;
color:#4F81BD;
font-style:italic;}
span.Char7
{mso-style-name:”批注框文本 Char”;
mso-style-link:批注框文本;}
span.HTMLChar
{mso-style-name:”HTML 预设格式 Char”;
mso-style-link:”HTML 预设格式”;
font-family:宋体;}
span.Char8
{mso-style-name:”编号 Char”;
mso-style-link:编号;
font-family:”Times New Roman”,”serif”;}
p.a, li.a, div.a
{mso-style-name:编号;
mso-style-link:”编号 Char”;
margin:0cm;
margin-bottom:.0001pt;
text-indent:0cm;
line-height:150%;
font-size:10.5pt;
font-family:”Times New Roman”,”serif”;}
span.sentence
{mso-style-name:sentence;}
p.a0, li.a0, div.a0
{mso-style-name:图;
mso-style-link:”图 Char”;
margin:0cm;
margin-bottom:.0001pt;
text-align:center;
text-indent:24.0pt;
font-size:12.0pt;
font-family:”Calibri”,”sans-serif”;}
span.Char9
{mso-style-name:”图 Char”;
mso-style-link:图;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.cp
{mso-style-name:cp;}
span.nt
{mso-style-name:nt;}
span.nb
{mso-style-name:nb;}
span.p
{mso-style-name:p;}
span.nx
{mso-style-name:nx;}
span.s2
{mso-style-name:s2;}
span.kc
{mso-style-name:kc;}
span.mi
{mso-style-name:mi;}
span.kd
{mso-style-name:kd;}
span.o
{mso-style-name:o;}
span.na
{mso-style-name:na;}
span.s
{mso-style-name:s;}
span.s1
{mso-style-name:s1;}
p.code, li.code, div.code
{mso-style-name:code;
mso-style-link:”code Char”;
margin-top:5.25pt;
margin-right:0cm;
margin-bottom:5.25pt;
margin-left:0cm;
text-indent:20.15pt;
line-height:10.0pt;
background:#F8F8F8;
border:none;
padding:0cm;
font-size:10.0pt;
font-family:Consolas;
color:#333333;
font-weight:bold;}
span.k
{mso-style-name:k;}
span.codeChar
{mso-style-name:”code Char”;
mso-style-link:code;
font-family:Consolas;
color:#333333;
background:#F8F8F8;
font-weight:bold;}
span.c1
{mso-style-name:c1;}
.MsoChpDefault
{font-size:11.0pt;}
.MsoPapDefault
{margin-top:10.0pt;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
line-height:115%;}
/* Page Definitions */
@page WordSection1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
–>

node-webkit教程(10)Platform Service之File dialogs

文/玄魂

目录

node-webkit教程(10)Platform Service之File dialogs

前言

10.1  File dialogs简介

10.2  打开一个文件对话框

10.3 多文件选择对话框

10.4  文件类型过滤

10.5  选择文件夹

10.6  保存文件对话框

10.7  FileList

10.8 指定默认路径

10.9 小结

前言

几个月前,要开发一个简易的展示应用,要求支持离线播放(桌面应用)和在线播放(web应用)。

当时第一想到的是flex,同一套代码(或者只需少量的更改)就可以同时运行在桌面和浏览器上。由于很多展现效果要全新开发,我想到了impress.js(https://github.com/bartaz/impress.js/)。如果选择impress.js,就意味着要将html5作为桌面应用,当时想到要封装webkit,但是本人对这方面也不是很熟悉,时间也很有限,就又沿着这个方向搜索,找到了node-webkit(https://github.com/rogerwang/node-webkit)。

node-webkit解决了我通过htmljs来编写桌面应用的难题

至于node-webkit的定义,按照作者的说法:

“ 基于node.js和chromium的应用程序实时运行环境,可运行通过HTML(5)、CSS(3)、Javascript来编写的本地应用程序。node.js和webkit的结合体,webkit提供DOM操作,node.js提供本地化操作;且将二者的context完全整合,可在HTML代码中直接使用node.js的API。”

node-webkit教程(10)Platform Service之File dialogs

从本篇文章开始,为您介绍Platform Services些列的API,本系列由以下类别:

·             App – 每个应用运行时全局api

·             Clipboard – 剪贴板

·             Tray – 状态栏图标,消息通知

·             File dialogs-文件选择对话框

·             Shell – 桌面相关

·             Handling files and arguments-处理文件和相关参数

10.1  File dialogs简介

文件操作是桌面应用最常使用的功能之一,相应的打开或保存文件的文件对话框也是最常用的组件之一。

在html中,我们可以通过

<input type=’file’ />

去打开文件对话框,上传文件到服务端。但是html中的文件对话框对于桌面应用来说,显然是不够的,没有办法知道文件的来源,不能保存文件到本地等。

node-wekit对html的文件对话框做了扩展,本文将对这些特性做详细的说明。下面创建示例应用。

新建dialog.html 和package.json作为本文的示例程序的原型。

dialog.html内容如下:

<html>

<head>

<title>dialogDemo</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

</head>

<body >

<h1>dialog 测试</h1>

<script>

// Load native UI library

var gui = require(‘nw.gui’);

var win = gui.Window.get();

</script>

</body>

</html>

package.json内容如下:

{

“name”: “dialog-demo”,

“main”: “dialog.html”,

“nodejs”:true,

“window”: {

“title”: “dialogDemo”,

“toolbar”: true,

“width”: 800,

“height”: 600,

“resizable”:true,

“show_in_taskbar”:true,

“frame”:true,

“kiosk”:false,

“icon”: “2655716405282662783.png”

},

“webkit”:{

“plugin”:true

}

}

10.2  打开一个文件对话框

修改dialog.html如下:

<html>

<head>

<title>dialogDemo</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

</head>

<body >

<h1>dialog 测试</h1>

<input id=”fileDialog” type=”file” />

<script>

var chooser = document.querySelector(‘#fileDialog’);

chooser.addEventListener(“change”, function (evt) {

apendText(this.value);

}, false);

function apendText(text) {

var element = document.createElement(‘div’);

element.appendChild(document.createTextNode(text));

document.body.appendChild(element);

}

</script>

</body>

</html>

首先,在代码中添加了“file”类型的input标签。

<input id=”fileDialog” type=”file” />

这就是一个普通的文件选择框,在script中,我们添加对改选择框的选择文件之后的事件监听代码,获取选择文件的路径。

var chooser = document.querySelector(‘#fileDialog’);

chooser.addEventListener(“change”, function (evt) {

apendText(this.value);

}, false);

运行效果如下:

node-webkit教程(10)Platform Service之File dialogs

node-webkit教程(10)Platform Service之File dialogs

node-webkit教程(10)Platform Service之File dialogs

10.3 多文件选择对话框

若要支持文件选择框支持多文件,只需要在input标签内添加“multiple ”属性即可,这是html5支持的属性。

<input id=”fileDialog” type=”file” multiple />

此时input的value值为所有文件的路径,以分号分隔。运行效果如下:

node-webkit教程(10)Platform Service之File dialogs

10.4  文件类型过滤

使用accept属性来过滤需要的文件类型,如:

<input id=”fileDialog” type=”file” multiple accept=”.html”/>

10.5  选择文件夹

选择文件夹,而不是文件,在桌面应用中更有用,因为我们可以通过后端程序(node.js)进行文件遍历。

使用nwdirectory属性,可以是input支持选择文件夹。

<input id=”fileDialog” type=”file” nwdirectory />

运行效果如下:

node-webkit教程(10)Platform Service之File dialogs

node-webkit教程(10)Platform Service之File dialogs

10.6  保存文件对话框

当我们想要把某些内容保存到文档,保存文件对话框就十分重要了,当然这也是传统浏览器应用不具备的功能。

使用nwsaveas  属性可以启动保存文件对话框。

<input id=”fileDialog” type=”file” nwsaveas />

运行结果如下:

node-webkit教程(10)Platform Service之File dialogs

可以设置默认文件名,如:

<input id=”fileDialog” type=”file” nwsaveas=”aa.txt”/>

10.7  FileList

在前面我们通过input标签的value属性获取选择的文件,Html5提供了files 属性,可以遍历文件。

修改示例程序的script,如下:

<script>

var chooser = document.querySelector(‘#fileDialog’);

chooser.addEventListener(“change”, function (evt) {

var files = this.files;

for (var i = 0; i < files.length; ++i)

apendText(files[i].name);

}, false);

function apendText(text) {

var element = document.createElement(‘div’);

element.appendChild(document.createTextNode(text));

document.body.appendChild(element);

}

</script>

运行结果如下:

node-webkit教程(10)Platform Service之File dialogs

在上图中,我们看到程序输出了选择的文件名,但是并没有完整的路径。node-webkit,扩展了一个名为path的属性,通过这个属性,可以获取完整的文件路径。继续修改代码:

for (var i = 0; i < files.length; ++i)

apendText(files[i].path);

运行结果如下:

node-webkit教程(10)Platform Service之File dialogs

10.8 指定默认路径

很多时候,我们需要引导用户从指定的目录打开或者保存文件,比如用户的文档目录,通过nwworkingdir属性可以完成这一需求。

修改input标签如下:

<input id=”fileDialog” type=”file”  nwworkingdir=”D:\xuanhunfile” />

在应用中打开文件对话框,会从指定目录开始。

node-webkit教程(10)Platform Service之File dialogs

10.9 小结

本文内容主要参考node-webkit的官方英文文档,做了适当的调整(https://github.com/rogerwang/node-webkit/wiki/File-dialogs)。

下一篇文章,介绍shell。

鄙视不标明出处的转载,更多相关内容,欢迎访问玄魂的博客(www.xuanhun521.com)

更多相关内容,欢迎访问玄魂的博客(更多node-webkit相关内容 http://www.xuanhun521.com/Blog/Tag/node-webkit)

ps:nw.js,electron交流群 313717550

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903