使用 AppJS ( http://appjs.org/ ),它基本上为 NodeJS 提供了一个 webkit 窗口来使用。 我正在尝试利用拖放事件来处理要在我的代码中使用的文件和 URL。
拖放的短代码可以在这里找到:https://github.com/appjs/appjs/wiki/HTML5:-Drag-&-Drop-from-Desktop
我用来创建窗口的代码:
var app_window = appjs.createWindow({
width : 200,
height : 200,
showChrome : true, //display as standard os window with max/min/close buttons
alpha: false,
autoResize: true, //adjust window size automatically according to content.
resizable: true, //allow user resize of window
margin: 0,
disableSecurity:true, //turn off security restrictions.
showResizeGrip:false, //show/hide the resize grip.
name:'Drag and Drop', //undocumented parameter
opacity:1,
fullscreen:false,
topmost:true
});
事件处理程序代码:
var window_drop = function(event) { // this code never fires.
event.preventDefault();
console.log('drop event');
};
以及我为触发事件设置的代码:
app_window.on('ready', function() {
app_window.require = require;
app_window.process = process;
app_window.module = module;
app_window.console = console;
app_window.frame.show();
app_window.frame.center();
app_window.addEventListener("drop", window_drop);
});
规范:我在 Mac OSX Lion 上运行 NodeJS 32 位(AppJS 需要)。
我知道 AppJS 还处于起步阶段,但这应该可行。
可能是什么问题?为什么事件从未触发?
最佳答案
我不完全确定为什么您的方法不起作用,但请尝试我使用的方法(并且有效):-
在您的主 html 中,在此处添加脚本标签,然后将您的放置事件附加到应用就绪事件中,如下所示:
addEventListener('app-ready', function(e){
window.addEventListener("drop", window_drop);
window.dispatchEvent(new Event('app-done'));
});
关于javascript - AppJS 拖放事件从未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16142980/