未来读者的解决方案:
“screen_shot.js”中的 Node.js 函数:
exports.getUserHome = function() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
index.html 中的标头 js:
$(document).ready(function() {
var sc= require('screen_shot');
$('.fileDialog').each(function(i) {
$(this).attr('nwworkingdir', sc.getUserHome() + '\\Pictures');
});
});
var sc= require('screen_shot');
function wait(e) {
var page = $(e).closest('[data-role="page"]');
$('#close-popup').click();
page.find('.fileDialog').click();
}
function screen_shot(fn) {
html2canvas($('body'), {
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png").split(',')[1];
sc.buildFile(fn, img);
}
});
}
$('["..."]').live("pagecreate", function() {
$(this).find('.fileDialog').change(function() {screen_shot($('.fileDialog').val() + '.png');});
});
$('[id^="..."]').live("pagecreate", function() {
$(this).find('.fileDialog').change(function() {screen_shot($('.fileDialog').val() + '.png');});
});
$('[id^="..."]').live("pagecreate", function() {
$(this).find('.fileDialog').change(function() {screen_shot($('.fileDialog').val() + '.png');});
});
对话框和按钮:
<input style="display:none;" class="fileDialog" type="file" nwworkingdir="" nwsaveas/>
<a href="#" onclick="wait(this);" data-role="button" data-theme="j">Save As</a>