aardio 拖拽外部文件到webview2 获得 本地文件路径 drag drop

aardio 默认的web.view 不支持,所以换个库

1|0官方的issue解决方案

https://github.com/MicrosoftEdge/WebView2Feedback/issues/2313

2|0webview2 库

https://github.com/aardiolib/webview2
这个库封装的事件很全面

安装方法

npm i @aardiolib/webview2 复制 .\node_modules\@aardiolib\ 到aardio软件目录 .\lib\

项目简单示例

import win.ui; import webview2; /*DSG{{*/ var winform = win.form(text="webview2 Demo";right=759;bottom=469) winform.add() /*}}*/ ..webview2.CreateCoreWebView2Environment(function(errorCode,createdEnvironment){ createdEnvironment.CreateCoreWebView2Controller(winform,function(errorCode, createdController){ winform.adjust = function(){ createdController.put_Bounds(winform.getClientRect()); } createdController.put_Bounds(winform.getClientRect()); createdController.put_IsVisible(true); var m_webView = createdController.get_CoreWebView2(); m_webView.Navigate("https://www.baidu.com/"); }) }) winform.show(); win.loopMessage();

添加 NewWindowRequested 事件处理程序
外部文件拖入后,默认是弹出个新框,然后就能获取到文件url了,然后再将url传递给网页的页面,或者直接执行操作,再刷新页面即可
args.get_Uri() 就是文件地址

import win.ui; import webview2; import console; /*DSG{{*/ var winform = win.form(text="webview2 Demo";right=759;bottom=469) winform.add() /*}}*/ ..webview2.CreateCoreWebView2Environment(function(errorCode,createdEnvironment){ createdEnvironment.CreateCoreWebView2Controller(winform,function(errorCode, createdController){ winform.adjust = function(){ createdController.put_Bounds(winform.getClientRect()); } createdController.put_Bounds(winform.getClientRect()); createdController.put_IsVisible(true); var m_webView = createdController.get_CoreWebView2(); //添加 NewWindowRequested 事件处理程序 m_webView.add_NewWindowRequested(function(args){ //console.log("NewWindowRequested",args.get_Uri()); args.put_Handled(true); //m_webView.Navigate(args.get_Uri()); }) m_webView.Navigate("https://www.baidu.com/"); }) }) winform.show(); win.loopMessage();

库里面有一些相应的示例

3|0最后用的这个老库

https://github.com/WDNLRuny/web.view2

sdk:64位

https://developer.microsoft.com/zh-cn/microsoft-edge/webview2/?form=MA13LH#download

https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/578353e9-31f2-45fc-85e2-312f11180aaf/MicrosoftEdgeWebView2RuntimeInstallerX64.exe

web.view2 已废弃,本项目已停止维护。请使用新版本webview2


__EOF__

本文作者Reciter
本文链接https://www.cnblogs.com/pengchenggang/p/18087021.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   彭成刚  阅读(230)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-03-21 Prettier 和 ESLint 冲突解决方案 eslint-config-prettier eslint-plugin-prettier
2019-03-21 css 两列 左侧列固定 width: 100px; float: left; 右侧列自适应 margin-left:100px; 注意要用在div上的style
2019-03-21 vscode F12 不能用,原来是快捷键冲突了。
2019-03-21 Vue.js Extension Pack 和 jsconfig.json 可以定位跳转到@开头的路径等自定义路径
点击右上角即可分享
微信分享提示