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.
WebView recibing Drag & Drop with full path of files?
Re: WebView recibing Drag & Drop with full path of files?
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.
You could also adapt this for images with reader.readAsDataURL and decoding the images from Base64.
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
