Working on a script for InDesign I found this problem : if I call app.open() from inside button.onclick() it stops and nothing happens. Since I'm a beginner with Javascript I'm probably doing something wrong. But if not, how do I fix? I can not find an alternative.
Please, only pure Javascript.
Thanks in advance.
Here the working code :
var book_info;
if (app.books.length != 1) {
var theFile = File.openDialog ("Select the book file to open...");
get_data(theFile);
alert(book_info.filePath + "\r" + book_info.name);
}
book_info.close();
function get_data(data) {
app.open(data);
book_info = app.activeBook;
alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
return data;
}
and here the one not working :
var book_info;
var w1 = new Window ("dialog", "TEST");
w1.minimumSize.height = 50;
w1.minimumSize.width = 50;
var p1 = w1.add ("panel");
sel_button = p1.add ("button", undefined, "Select book");
var g1 = w1.add ("group");
g1.add("button", undefined, "Cancel");
g1.add("button", undefined, "OK");
sel_button.onClick = function(){
var theFile = File.openDialog ("Select the book file to open...");
get_data(theFile);
alert(book_info.filePath + "\r" + book_info.name);
book_info.close();
};
w1.show();
function get_data(data) {
app.open(data);
book_info = app.activeBook;
alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
return data;
}