HTMLViewer Link Clicked Event?!

Isn’t there an event triggered when someone clicks a link () being displayed in an HTMLViewer?! I could have sworn that a tutorial I read/listened to mentioned, “If your user clicks on a link, it’s up to you to send them to that page.” I’ve searched the Internet and this forum, and nowhere have I found a simple explanation of how to intercept link-clicks in an HTMLViewer.

Someone, please show me the way! Thank you! :slight_smile:

if the link will open a new window write ‘return me’ in the NewWindow Event of HTMLViewer

@Axel Schneider , thanks for the help!

I put a simple MsgBox(“Clicked”) in the NewWindow event of the HTMLViewer, and I get no response when I click on a link. What am I doing wrong?

I tried ending that event code with nothing, with “Return Me” and “Return Nil.” None worked as expected… :-/

What happens inside the HTMLViewer is under control of Webkit (or the rendering engine), meaning that you should control, detect, Etc. with the javascript, html, Etc. contained inside the webpage code. Am not sure that the NewWindow event fires when you click on a link, because of that.

Anyway, if you want to intercept via the Xojo program, you could detect the DocumentBegin() event. It returns the URL it is navigating to. If the URL is not allowed or you want to redirect, use the Cancel method, and redirect with LoadURL.

OK, I goofed. I had the cursor changing to a pointer over a certain part of the page, but that certain part wasn’t necessarily a link, so clicking on it didn’t trigger like a link-click should. Now that I’m clicking in the right place, I’m getting responses in both NewWindow and DocumentStart.

Confused. I actually did have the image wrapped in the , but only when I click the text within the does the click trigger. Guh.

Still… Thank you, guys! I’ll keep you posted…

I did a small test app (OSX).

  • NewWindow fires only if I right click on a link and specify open in a new window, or if the link opens with “_blank”.

  • DocumentBegin fires everytime you navigate to other page within the same window. Strangely it fired repeatedly on youtube. Perhaps it has some reloading with ajax or so.

  • I don’t see an event named DocumentStart…

[quote=220617:@Julio Debroy]I did a small test app (OSX).

  • NewWindow fires only if I right click on a link and specify open in a new window, or if the link opens with “_blank”.

  • DocumentBegin fires everytime you navigate to other page within the same window. Strangely it fired repeatedly on youtube. Perhaps it has some reloading with ajax or so.

  • I don’t see an event named DocumentStart…[/quote]

Thanks, @Julio Debroy . I will add “_blank” to all my links and see what happens.

DocumentStart is an alias for DocumentBegin… in my own mind. :smiley: (haha… Just a typo. Oopsies.)

Haha I supposed it was a mental Alias

I’m having great success by adding a “target=”"_blank""" attribute to all the links. Works great! Thanks for the heads-up @Julio Debroy !

i need to open a simple _blank in my htmlviewer… but i dont know how… :frowning: please help

https://forum.xojo.com/29213-htmlviewer-not-opening-targeted-urls/0