Ran into a weird problem with one of my webSDK plugin controls yesterday and I want to share the info in case others hit the same thing. Im not sure if its a bug or just something I didnt understand properly.
I was calling to executeJavascript to change the innerHTML of my plugin control. I altered the original working code by adding an onload handler to send a server event to me to let me know the image had loaded properly. The code originally looked like this:
“<img id=”"" + self.ControlID + “_img” src=""" + currentLink + “”" style="“max-width:100%; max-height:100%; vertical-align:middle;”"/>
which worked fine, and then I added the onload handler like this:
“<img id=”"" + self.ControlID + “_img”" onload=“Xojo.triggerServerEvent(’” + self.ControlID + “’, loaded’);”" src=""" + currentLink + “”" style="“max-width:100%; max-height:100%; vertical-align:middle;”"/>"
notice the single quote around the embedded triggerServerEvent call parameters and ignore the fact that the browser as tried to make some of them into fancy UTF8 quotes… This worked fine on a regular page, but blew up with a Unexpected identifier javascript error when the control was on a webDialog. I have no idea whats different about setting the innerHTML of something on a web dialog, but replacing those single quotes with ' allows the control to work on regular pages and on a web dialog.
the final snippet that is working everywhere now looks like this:
“<img id=”"" + self.ControlID + “_img”" onload="“Xojo.triggerServerEvent(’” + self.ControlID + “’, ‘loaded’);return false;”" src=""" +
Which is horribly messy and difficult to read, but such is life when youre writing code that writes code that includes code