Skip to main content
Known Participant
August 16, 2019
Question

How to wait for the "loaded" event in bridge extendscript?

  • August 16, 2019
  • 1 reply
  • 2994 views

According to the scripting guide:

A script should wait until the loaded event has occurred

before making calls to document selection methods.

Sounds good to me, but how do I "wait" for this event?

This topic has been closed for replies.

1 reply

SuperMerlin
Inspiring
August 16, 2019

Here is an example:-

onDocLoadEvent = function( event ){

if(event.object instanceof Document){

    if( event.type == "loaded" ){

          //Your code goes here

            }

        }

        return { handled: false };

}

app.eventHandlers.push( { handler: onDocLoadEvent} );

Known Participant
August 16, 2019

I've tried that. Problem is the loaded event is occurs multiple times. I only want to run my code after the first time.

SuperMerlin
Inspiring
August 16, 2019

You could set a counter:-

app.eventHandlers.push( { handler: onDocLoadEvent} );

var count = 0;

function onDocLoadEvent( event ){

if(event.object instanceof Document &&  event.type == "loaded" ){

if(count == 0) doSomething();

count++;

    }

    return { handled: false};

};

function doSomething(){

    $.writeln("Got Here");

    }