Page 1 of 1

addEventListener execute JSX only the first time

Posted: Tue Dec 27, 2016 8:45 am
by ApWizard
as the subject suggests while testing some listener I found this strange behavior: the addEventListener does get triggered, the callback get called but the evalScript invoking the JSX runs only the first time.

This is how I'm doing it:

Code: Select all

function doSomething(){
 document.getElementById("placeholder").innerHTML += "+";
        document.getElementById("docName").innerHTML += result + ", ";

var csInterface = new CSInterface();

in the JSX I have:

Code: Select all

JSXdoSomething = pleaseDo()
function pleaseDo(){

now, when switching between documents, this line get executed every time:

Code: Select all

document.getElementById("placeholder").innerHTML += "+";

but the evalScript works only the first time.

PSA: if you already have a document opened and you open the extension documentAfterActivate gets fired.

we have 2 documents open: Doc1 and Doc2
the output I'm getting while switching between the two:
"placeholder" = ++++++...
"docName" = Doc1, Doc1, Doc1, Doc1...

I've also tried to call the evalScript in this way:
a) csInterface.evalScript("pleaseDo" ...
b) csInterface.evalScript("pleaseDo()" ...

for a) I get the same behavior as described above and for b) I get "EvalScript Error."

I tried to change the JSX in this way:

Code: Select all

$._doSomething = function(){

and call it like this:
csInterface.evalScript("$._doSomething" ...

I get the same behavior as before: the evalScript get executed only the first time and for the subsequent times the value stored in the return is always the name of the first Document. I've also tried to put an alert in the JSX function and sure enough I don't get the pop-up every time I change the document but only the first time.

Have you played with the events? Can you point me in the right direction? :)