Hi There,
In xojo 2.0, I would like to ask if there is a chance to call xojo method inside html imbdeded on a webhtmlviewer? If yes, is there a working sample script on how to accomplish it?
Hi There,
In xojo 2.0, I would like to ask if there is a chance to call xojo method inside html imbdeded on a webhtmlviewer? If yes, is there a working sample script on how to accomplish it?
The short answer is “no”.
The long answer is that you can create a method to do this using URL parameters in a link or AJAX request with the Session.Identifier and data to send information back to the Xojo web app which you would then handle in the App.HandleURL event and forward the data to the target WebSession. It’s not easy, but it’s doable.
I don’t recommend it, and you should instead use the WebSDK.
I’ve passed really simple callbacks from my WebHTMLViewer controls using HashtagChanged, but that’s limited to really simple things (such as navigating).
You can see it done with the live demo of TPLM. Clicking the IP address in the overview panel sends you to the Activity Log using a simple <a href="#ActivityLog"> and HashtagChanged.
Anthony’s right though, for more involved things the WebSDK is the correct way to build custom controls.
I agree that the WebSDK is the “proper” way to go.
However, there are workarounds. Take a look at @Tim_Dietrich’s blog post: Xojo: Web 2.0 Code Injection Technique.
Using this approach, I built myself a WebHTMLViewer subclass that supports executeInXojo/JavascriptRequest.
It’s janky, but reliable.
Um… wait a sec guys. It matters what he’s loading. If it’s a whole page then yes, your answers are correct, but if he’s just loading html snippets, it absolutely can be done. I use that all the time when creating controls.
Oh? I’m very interested. The best I came up with was HashtagChanged. Tim D’s system is a bit too far beyond “hack” for my comfort.
What is your method?
HTML snippets are embedded within a DIV on the page while entire pages are embedded in a Iframe. So it is possible if it’s just an HTML snippet to execute the JavaScript in the app context. I’d still recommend using the WebSDK.
I think OP wants to send a message back to the server and execute a Xojo method. This is what I am curious about doing without massive hacks. I’ve solved my needs so far, but it’s so easy to quickly bang out a Bootstrap component in a WebHTMLViewer when you need something the framework is missing.
I made a control using the WebSDK that’s specifically designed to receive events. It also has a method on it for generating the necessary call. Lemme see if I can whip up an example.
Edit: Ah, it’s in the WebSDK Examples folder next to the IDE. It’s called Callback Example.xojo_binary_project
I can’t find it. It is available in built-in xojo example?
Thanks!
This really works!