I have a JavaScript function that gets the document reference of the current document. However, if there is no document open, it falls over and does not return 'null' as intended. How do I change the following code to check first that there is a document open before trying to execute the rest of the code?
Code: Select allfunction getDocRef() {
var docRef = activeDocument;
if (docRef != null) {
return docRef;
}
else {
return null;
}
}
Thanks.
Check for open document.
Check for open document.
You could try this?
Code: Select allfunction getDocRef() {
if (app.documents.length == 0) return null;
var docRef = activeDocument;
if (docRef != null) {
return docRef;
}
else {
return null;
}
}
Davide
Code: Select allfunction getDocRef() {
if (app.documents.length == 0) return null;
var docRef = activeDocument;
if (docRef != null) {
return docRef;
}
else {
return null;
}
}
Davide
Check for open document.
You could try this..
Code: Select allfunction getDocRef() {
if(!documents.length) return null;
return activeDocument;
}
Code: Select allfunction getDocRef() {
if(!documents.length) return null;
return activeDocument;
}