Referencing a Javascript object

I’ve got a WebHTMLViewer on a dialog named “Uppy1”. In the WebHTMLViewer’s shown event, I am executing Javascript using me.ExecuteJavascript that creates a Javascript object that is part of an open source library. So far everything is working well. I even got a call back to work with a custom WebSDK control that I am placing on the WebDialog.

Here is the Javascript code that is executing to create the object:

var uppy = new Uppy.Core()
        .use(Uppy.Dashboard, {
        inline: true,
        target: '#drag-drop-area',
        showLinkToFileUploadResult: false,
        disableThumbnailGenerator: true,
        showProgressDetails: true,
        allowMultipleUploads: false,
        hideProgressAfterFinish: false,
        height: 400, 
        width: 400

I would like to execute a method on the “uppy” object using Javascript when a Xojo Web Button is clicked. For starters, I am trying something really simple:


When I run this, the first statement seems to be ignored and all I get in the console log is “testing”.

I’m guessing it is a scope issue but I have no idea where to start. How do I access the Javascript “uppy” object that I create in the open event of the WebHTMLViewer?

At the point you’re running the second bit of code, the uppy variable has gone out of scope. You can set it as a global variable by doing something like:

window.uppy = new Uppy.Core();

The first console line doesn’t appear to execute because uppy is undefined at that point and you’re calling getId on an undefined object, which raises an exception in JavaScript.

1 Like

That did it! Thanks Anthony!

Happy to help. Bear in mind that uppy will now exist everywhere in your app, and if you use multiple instances you may run in to issues.