i have a script which checks for all the broken links. If i find a broken link i want to close the current document.
I tried with app.close() from within the afterOpen event. and i get an error "cannot close document because it is the target of an active event".
how do i stop the propagation of the event or a workaround to trigger the close of document from wthin the event.
I am not sure this would be a good idea, how could you ever fix the document if you close it when it has a broken link, everytime you open the document your afterOpen would fire, and then your document would close, so you could never open the document to fix the broken link.
Maybe I am misunderstanding your use case but this would certainly not be considered good user experience if the document opens and then closes and I wouldn't know why.
But I guess you could store something from the afterOpen event globally, and then have a script that runs every so often ( not sure what the best method for that would be) and if the global variable is set (with say a document name) it could close that document.
Hi @Ajith5F94 ,
technically spoken, workflow issues aside, you could open the document from app without a visible layout window so that the user has no direct access. Why that should be or not is a different discussion.
var myDoc = app.open( DocFile , false );
Then do your checks on broken links. Alert the user that the document has issues that should not be fixed right now and he/she should work on a different one. Now close the document without saving:
myDoc.close( SaveOptions.NO );
In case all is ok with the invisible document add a layout window to the invisble document with:
Now the user is able to see the layout window of the opened document.
Hm. That all said…
This is a workflow where the actual user absolutely has no business with correcting broken links.
( Adobe Community Professional )