Downloading a file with HTMLViewer

I want to have an HTMLViewer download a file when one clicks on the link. I understand this will require the use of an separate socket, which is fine. What I can’t figure out is how to tell in the DocumentComplete event (or any event) how I can know that the URL is pointing to downloadable content. Is it possible to determine that in any of the HTMLViewer events? If not, is there a Declare for that? Thanks.

Mac? Win? Linux?

For Mac you can use WebDownloadDelegateMBS class in MBS Plugins.
https://www.monkeybreadsoftware.net/class-webdownloaddelegatembs.shtml

Mac. I can look at MBS. But I had hoped that there was a Xojo-native way to handle this (or at least a declare). Thanks.

a lot of work with declares to make delegate class. This is easier to implement via plugin and already done :slight_smile:

Easiest and fastest is probably to use Christian’s plugins
Declares are doable, but lots of work
You might be able to do it using the CancelLoad event and doing a peek at the HTTP headers using a helper socket…

Quick and dirty you can look at the extension of the file in CancelLoad. If anything like .zip, .tar, or whatever file you expect to be downloaded you download it via an HTTPSocket. This won’t work for php scripts that use arguments to fetch the download, though.

All depends on what you need. I would go for the MBS plugin if this is to go to the general public. It will save you a lot of aggravation.

Hello, I’m trying the same as Jonathan. How can I use the plugin? I tried but I can’t get it

this I have made 2013 to learn
maybe it works for you

see browser.DocumentBegin (where I have specified some file extensions)

Thanks a lot!

you can install MBS Cocoa plugins, and make a new subclass of WebDownloadDelegateMBS.
Than you fill in code in events.
Than you install the delegate handler.

HTMLViewer1.InstallWebDownloadDelegateMBS dd

as you see in the example code here:
https://www.monkeybreadsoftware.net/example-cocoacontrols-htmlviewermac-webdownloaddelegatembstest.shtml

[quote=181860:@Christian Schmitz]you can install MBS Cocoa plugins, and make a new subclass of WebDownloadDelegateMBS.
Than you fill in code in events.
Than you install the delegate handler.

HTMLViewer1.InstallWebDownloadDelegateMBS dd

as you see in the example code here:
https://www.monkeybreadsoftware.net/example-cocoacontrols-htmlviewermac-webdownloaddelegatembstest.shtml[/quote]
But Only works On Mac. Not for Linux or Mac. :frowning:

I check the link in the cancelLoad event, if it’s not something I want displayed in the HTMLViewer, I do what I need and then return true.

So you could do something like:

[code]if right( url, 4 ) = “.zip” then
// — Pass off to download socket

return true
end if[/code]