HTMLViewer - identify which local file types can be viewed?

In my project (for Mac and Windows desktop), I have a listbox (lb) that displays the names of local files on the user’s computer and saves the corresponding FolderItem (f) in the RowTag. In the lb.Change event, the file is displayed in an adjacent HTMLViewer - hv, whose renderer is WebKit - using hv.LoadPage(f).

The files I want to display are mostly pdfs and images which will display OK in the HTMLViewer. However, if the file type can’t be displayed, I want to capture this so that I can open the file in the default program instead, using f.Open.

On Mac, if the file is, for example a .docx, then with hv.LoadPage(f) the following sequence of events are fired:
Error (102, Frame load interrupted)

So I can use the Error event to go down my alternate pathway. However, on Windows, only the CancelLoad event fires and that’s it. If I change the renderer to Native, then a modal dialog pops up asking if I want to download the file, which is not the desired behaviour.

Does anyone have suggestions on how I could implement this on Windows? Or is there are more elegant way to achieve the desired result?


Check the file extension and decide what to do; if .pdf, .gif, .png, .etc… : display, Else, do nothing.

Thanks for the suggestion. I’d like to avoid hard coding specific extensions, if possible, as I think which file types can or can’t be displayed might vary with the users OS and plugins.

In the end, I decided to make use of the lack of the DocumentBegin event. I added a property WaitingForDocumentBegin as Boolean. Just before trying to load the doc in the HTMLViewer, I change WaitingForDocumentBegin to true, and run a Timer in Modes.Single that waits 200ms then checks the value of WaitingForDocumentBegin. (In the DocumentBegin event, I set it to false). This way, I can tell if the document has loaded or not.

It’s not elegant and I’m sure the functionality will be broken at some stage by a change in HTMLViewer, but it works for now :stuck_out_tongue: