Allow JavaScript in Desktop HTMLViewer

another site

This rises another question as the docs are ultra superficial. At what moment this event is fired? Multiple random times during a large load giving the user the chance to abort? One time just before
DOMContentLoaded()? One time after DOMContentLoaded()? Any other option?
Also canceling the loading also does not stop the engine? I mean, the event sequence stops (load event never fires for such page for example? Other things die too?) and the page gets broken?

I use this in a couple of places to ensure that a URL clicked in the HTMLViewer is shown in the user’s browser rather than the Viewer. Here is what I ended up with - I commented this more than I might otherwise have done (I have a built-in WebSocket server to handle Win/Lin mailto: requests) since it seems multiple events occur. Hmm, possibly some of this might be out of date now.

Sub CancelLoad (URL as String) As Boolean

// 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 in the user's browser. 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 via an AppleEvent triggered by the GotoURL. For
// Win/Lin, it is handled via the mailtoWSserver, so nothing should be done here.

if  (URL="about:blank" or URL.BeginsWith("file://"))  then Return False

#if  (TargetWindows=True)  then
  if  (URL.BeginsWith("data:") or URL.BeginsWith("c:\Users\"))  then Return False
#EndIf

#if  (TargetMacOS=False)  then
  if  (URL.BeginsWith("mailto:"))  then Return True           // The HTMLViewer should ignore this request
#EndIf

system.GotoURL (URL)

Return True

End Sub

I see, so the CancelLoad is not a CancelLoad() (interrupt the page loading started) but an AllowLoading() (only the page replacement or more resources IN the page?) with an inverse boolean as result; true=don’t allow, false=allow (allow or deny a request to load).

Docs needs extra clarifications and mentioning about when it fires and relation with internal links in the current loaded page firing them too.

Current docs. 1 line:

image

Returning True prevents the existing content of the Viewer from being replaced. Returning False allows the loading of the Viewer to proceed.

It must be incorrect. It adds unnecessary cost. It probably aborts the request never really loading something.

Of course, you don’t have to implement the event. In which case loading proceeds.