How to capture clicks on links in HTMLViewer

  1. 3 months ago

    Thomas T

    May 6 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    Edited 3 months ago

    I'm trying to write my first Web app with Xojo. It'll be a port of a working Desktop app.

    I need to render some custom html in a window and need to react to clicks to links inside that html view, in order to update other controls in my window, or alter the html.

    I am using a HTMLViewer control and call LoadPage to load my html code.

    But I cannot find any event that lets me capture clicks on the links so that I can react to them.

    How does one do that? Could I set the hrefs to some address that calls back to my app, perhaps?

    Or does MBS offer something for that, like it does in desktop apps? I suspect there are no plugins for Web though, right?

    If you're completely in charge of the HTML being displayed I would also recommend looking into the WebSDK. You can have your links trigger Xojo events that are session aware. This should all work if the only reason you were using a HTMLViewer was to display HTML you created.

  2. Christian S

    May 6 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    This sounds like use for WebSDK.
    But usually JavaScript from iFrame to your web app is not allowed.

  3. Thomas T

    May 6 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)

    Not allowed by whom? By the law? By Xojo? By Web Browsers?

  4. Tim P

    May 6 Pre-Release Testers Rochester, NY

    By law. Well, by web browser security. The techniques have been proven to be used in malicious ways in the past, so as standard security you can't operate javascript on an iframe displaying a different domain or protocol.

  5. Thomas T

    May 6 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)
    Edited 3 months ago

    Thanks, Tim.

    So that leaves creating URLs in my href links that directly call back into the app's URL handler.

    Anyone done that?

    I mean, how does that work? I see that the framework creates links that refer to the session ID, so I guess I have to do that as well, but how do I receive those?

  6. Tim P

    May 6 Pre-Release Testers Answer Rochester, NY

    If you're completely in charge of the HTML being displayed I would also recommend looking into the WebSDK. You can have your links trigger Xojo events that are session aware. This should all work if the only reason you were using a HTMLViewer was to display HTML you created.

  7. Michel B

    May 6 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 3 months ago

    If what you want to do is click on some of the links, you could simply use a HTTPSocket to get the page content.

    You can then parse the content of the page, looking for 'a href' tags, and build a list of links.

    Then no need to intervene in the page itself.

  8. Thomas T

    May 6 Pre-Release Testers, Xojo Pro Europe (Germany, Munich)

    Tim, I had not realized that the WebSDK was doable in pure Xojo. Thanks for pointing it out, it sounds exactly like what I need.

  9. Tobias B

    May 6 Pre-Release Testers, Xojo Pro Bern, Switzerland

    look to

    Extras/WebSDK/Examples/HTMLArea.xojo_binary_project

    that should implement a stub of exactly what you are trying to accomplish.

  10. David C

    May 7 Pre-Release Testers, Xojo Pro Derby, ITM

    You can react to a changed URL ie if they click a specific button that loads a specific page, you get an Event, and can Action that.

    I use this to know if the user has paid for an item via PayPal, as I have told PayPal to jump to a specific web page (on my web site, saying Thank you) on completion of the sale.

or Sign Up to reply!