The Basics

Editing

Web Publishing

Scripting

Dynamic Content

Events

Palettes

Managing Links, Pages, and Importing

VoodooPad on your iOS Devices

Security and Privacy

Miscellaneous

Document Events

Document events are a way to run JavaScript code when documents are opened, about to be closed, and closed.

To get started with document events, you'll first want to create a page in your document named "VPDocumentEventScript". This will automatically create a page with some required functions as shown below. You may then fill in your own code to open up new pages or perform other actions based on these events.

Make sure to check out the Sample Document Events page for examples.

Here is the default VPDocumentEventScript page:

/*
 Called when a document is opened.
 */

function documentWasOpened(document) {
    print("documentWasOpened: " + document.lastComponentOfFileName())
}


/*
 Called when a document is about to be closed.
 */
function documentWillClose(document) {
    print("documentWillClose: " + document.lastComponentOfFileName())
}


/*
 Called when a document is closed.  Note that a document object is not passed to this function.
 Instead, the path of the document that was open is called, since it's not safe to call methods
 on a closing document.
 */
function documentWasClosed(documentPath) {
    print("documentWasClosed: " + documentPath)
}