Page 1 of 1

WebView recibing Drag & Drop with full path of files?

Posted: Sat Feb 07, 2026 7:48 pm
by ricardo3
Hi,

Im developing some interface using webview but want to receive the full path (C://myfile.txt) of files dragged. Its possible, per example, to receive the drag and drop events in the pb window? I mean , receive the files in webview but detect it on my window? Because webview for security dont receive full path.
Thanks in advance.

Re: WebView recibing Drag & Drop with full path of files?

Posted: Sun Feb 08, 2026 3:00 am
by wombats
I don't think you can get the full path, like you said. You can load the files with FileReader. I think it might be slow with large files, though.

Code: Select all

Global file.s
file + "<!DOCTYPE html>" 
file + "<html>" 
file + "<head>" 
file + "</head>" 
file + "<body>" 
file + "<script>" 
file + ~"document.addEventListener(\"dragover\", (e) => {" 
file + "  e.preventDefault();" 
file + "});" 
file + ~"document.addEventListener(\"drop\", (e) => {" 
file + "     e.preventDefault();" 
file + "     const items = e.dataTransfer.items;" 
file + "     const item = items[0];" 
file + "     const file = item.getAsFile();" 
file + "     const reader = new FileReader();" 
file + ~"    if (item.type === \"text/plain\") {" 
file + "       reader.onload = () => {" 
file + "         window.OnDrop(reader.result);" 
file + "       };" 
file + "       reader.onerror = () => {" 
file + ~"        window.OnDrop(\"Error\");" 
file + "       };" 
file + "       reader.readAsText(file);"
file + "     }" 
file + " });" 
file + "</script>" 
file + "</body>" 
file + "</html>" 

Procedure DropCallback()
  Debug EventDropFiles()
EndProcedure

Procedure OnDrop(jsonStr.s)
  Protected json.i
  json = ParseJSON(#PB_Any, jsonStr)
  MessageRequester("", GetJSONString(GetJSONElement(JSONValue(json), 0)))
  FreeJSON(json)
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "", #PB_Window_SystemMenu | #PB_Window_Invisible)

WebViewGadget(0, 0, 0, 400, 400, #PB_WebView_Debug)
SetGadgetItemText(0, #PB_WebView_HtmlCode, file)

BindWebViewCallback(0, "OnDrop", @OnDrop())

HideWindow(0, #False)

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
You could also adapt this for images with reader.readAsDataURL and decoding the images from Base64.