I’m using HTMLViewer to display some email and web URL’s (from contacts) as hyperlinks but the results seem inconsistent.
Firstly mailto: doesn’t seem to link at all - ie it doesn’t open a new email in Mail.
Secondly http:// is inconsistent. Some sites work with http:// (e.g. Apple), whilst others only work with https:// (eg xojo).
For mailto URIs you will need to catch them in the CancelLoad event and handle the new email command.
Such as this:
If url.beginswith("mailto:") then
showUrl(url)
return True
End if
As for http:// working in some cases it must be caused by the redirection method used by the server. As to why apple.com works and xojo.com does not, I cannot explain it.
Unfortunately the OP didn’t indicate what platform he’s using. Here’s what I do in CancelLoad:
// Called when the content of the HTMLViewer is about to be replaced. If this is due to loading
// an html string into the control, then it seems the URL will be "about:blank". If it happens
// due to the user clicking on a link in the HTMLViewer, we want to show that one. Any links in
// the control will either have no "target" attribute, or it will have been be changed to "_self".
// This will force all clicked links to trigger this event, which then uses GotoURL() to display
// the linked page in the user's browser, rather than here.
//
// Under Win7 the page loaded from code goes via a temporary file. When an external link is
// clicked, the URL has the normal form, but also another event occurs with the "about:blank" URL.
//
// For macOS, mailto: is handled by an AppleEvent triggered by the GotoURL. For Win/Lin, it is
// handled otherwise, so nothing should be done here.
if (URL="about:blank" or URL.BeginsWith("file://")=True or URL.BeginsWith("c:\Users\")=True) then Return False
#if (TargetMacOS=False) then
if (URL.BeginsWith("mailto:")=True) then Return True // The HTMLViewer should ignore this request
#EndIf
system.GotoURL (URL)
Return True
OK I deduce he is on macOS. Then what I have posted will work.
The thing to do is to implement all the event handlers for HTMLViewer and see which ones fire under which circumstances. It’s what I did and that gave me the info I needed (along with reading the docs).