Download a file with the browser widget?

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Download a file with the browser widget?

Post by Klaus » Thu Dec 08, 2022 6:11 pm

HI all,

any hints on how to download a file with the browser widget?
I already tried e.g. to load a PDF file:

Code: Select all

on browserNavigateBegin pUrl
   if pURL ends with ".pdf" then
      libURLDownloadToFile pUrl, (specialfolderpath("dektop") & "/test666.pdf")
   else
      pass browserNavigateBegin
   end if   
end browserNavigateBegin

on browserDocumentLoadBegin pUrl
  if pURL ends with ".pdf" then
     libURLDownloadToFile pUrl, (specialfolderpath("dektop") & "/test666.pdf")
  else
     pass browserDocumentLoadBegin
  end if   
end browserDocumentLoadBegin

on browserUnhandledLoadRequest pUrl
   if pURL ends with ".pdf" then
      libURLDownloadToFile pUrl, (specialfolderpath("dektop") & "/test666.pdf")
   end if
end browserUnhandledLoadRequest
No file on my desktop!?
On my Mac the browser simply displays that clicked file.

I would like to "catch" the users click on a link on the current displayed webpage and NOT pass it.
Something like "on linkclicked tLink" for text fields.

Any hints highly appreciated!

Best

Klaus

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Download a file with the browser widget?

Post by SparkOut » Thu Dec 08, 2022 9:00 pm

If I remember rightly from libUrl, browserBeforeNavigate is what you need. (Or revBrowserBeforeNavigate.)
If I also remember rightly, there are some subtle differences with the browser widget (some bugs in either/both).

I did have a tester stack somewhere which did work the same with different code for both revBrowser and the browser widget. When I get to my computer I will try and find it.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download a file with the browser widget?

Post by Klaus » Thu Dec 08, 2022 9:04 pm

Just tested, no success, the widget just goes to the url. :?

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Download a file with the browser widget?

Post by SparkOut » Thu Dec 08, 2022 9:11 pm

Widget does need something different.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download a file with the browser widget?

Post by Klaus » Thu Dec 08, 2022 9:22 pm

Just tested with -> browserNavigateBegin, no dice.
I think I have tested all possible messages in the widget without success.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Download a file with the browser widget?

Post by SparkOut » Thu Dec 08, 2022 11:09 pm

I found part of the tester, here is what I played with.
(It was intended to try and see how to make a limited function "kiosk" browser for intranet rather than public internet. There's a list of allowed domains in a custom property of the browser widget. A few buttons set the chosen URL and then the card script detemines whether the domain is allowed or blocked, and allows navigation or resets the htmlText instead. I've added a test for .pdf suffix and will halt the navigation too, and download the file - which I found had to be done by "put url .. into url ("binfile:" & ...)

I know this "kiosk" test failed to be able to print, so "somewhere" I have another version that used "old" revBrowser, which I can't find now.
Browser Test.zip
(1.77 KiB) Downloaded 76 times

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download a file with the browser widget?

Post by Klaus » Fri Dec 09, 2022 9:59 am

Thanks a lot, will try later today!

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Download a file with the browser widget?

Post by Klaus » Fri Dec 09, 2022 11:25 am

YES!
VERY clever solution! Thanks a bunch!
Works fine, I added -> go back in widget 1 after the download, cool. :-)
Seems to be the only way to cancel the display of the clicked url.

My script:

Code: Select all

on browserNavigateBegin pUrl
  lock screen
  if pURL ends with ".pdf" then
    libURLDownloadToFile pUrl, (specialfolderpath("desktop") & "/test666.pdf")
    go back in widget 1
  end if
 unlock screen
end browserNavigateBegin

Post Reply

Return to “Internet”