Copy link to clipboard
Copied
I have javascript file (.js) with some functions I would like to use that functions inside extendscript file(.jsx). Both javascript and extend script are part of extension.
I known for:
var csInterface = new CSInterface();
csInterface.evalScript..
With this above I can use function from extedscript inside javascript but how I can do reverse process use functions from javascript inside extendscript?
What you can do is use CSXS events which are dispatched from the jsx when you need to call the js function. The js will already have a event handler registered for this event, inside this event handler you can call your js method and on completion of this method call you can call a jsx method using CSInterface to return back the retrurn data if any from jsx to js. To create a CSXS event you can use the following sample code
try {
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That code that is inside .js is not supported by .jsx (extendscript do not have all features of modern javascript) it will not run.
So it is not something that #include will solve.
It needs some workaround.
Copy link to clipboard
Copied
What you can do is use CSXS events which are dispatched from the jsx when you need to call the js function. The js will already have a event handler registered for this event, inside this event handler you can call your js method and on completion of this method call you can call a jsx method using CSInterface to return back the retrurn data if any from jsx to js. To create a CSXS event you can use the following sample code
try {
var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
} catch (e) {
}
if (xLib) {
var eventObj = new CSXSEvent();
eventObj.type = "eventType";
eventObj.data = "event data";
eventObj.dispatch();
}
-Manan
Copy link to clipboard
Copied
Nice, thank you!
On this link there are some documentation about "Access HTML DOM from extend script":