现在有一个 windows 程序,需要打开两个 webview ,显示不同的 UI components
比如 component a, http://a.sample.com/componenta/index.html component b, http://b.sample.com/componentb/index.html
想问一下,这两个 webview 的 components ,能够通讯么?
比如,使用 localstorage ?
现在有一个 windows 程序,需要打开两个 webview ,显示不同的 UI components
比如 component a, http://a.sample.com/componenta/index.html component b, http://b.sample.com/componentb/index.html
想问一下,这两个 webview 的 components ,能够通讯么?
比如,使用 localstorage ?
|
ch2Apr 28, 2022
1
跨域就不行
|
|
ktqFDx9m2Bvfq3y4Apr 28, 2022
2
@ch2
这问题不大,都本地程序了。基本上都可以让 JS 与程序本身互调用的,基于此就可以让他们通讯。再不济你程序架一个本地 HTTP 让他们互通。 |
|
IvanLi127Apr 28, 2022
3
postMessage ?
|
|
LLaMA2Apr 28, 2022
4
在 windows 上做个 bridge ,然后 js bridge 完成功能
|
|
3dwelcomeApr 28, 2022
5
如果是 electron 的 webview ,可以用 Node-API 作为中间桥梁来传参数,桥接方法有一大堆,随便写。
|
|
6
@ye4tar 不好意思,这个没看懂。做一个什么 bridge? 有没有相关 doc/wiki?
@IvanLi127 postMessage 不行吧? https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it. 我这两个 page ,没有 pop-up 关系...... |
|
snoopyhaiApr 28, 2022
7
postMessage 是否可行? https://developer.mozilla.org/zh-CN/docs/Web/API/Window/postMessage
|
|
snoopyhaiApr 28, 2022
9
|
|
AV1Apr 28, 2022 via Android
10
都 webview 了,用它所在的程序转发就好了。
|
|
zlu1123Apr 28, 2022
11
你的意思是同一个 app 中,两个 webview 通信嘛?可以用 js bridge
|
|
auroracccApr 28, 2022
12
你在 http://a.sample.com/componenta/index.html 里 window.open http://b.sample.com/componentb/index.html 就能拿到 b 窗口了,然后通过 postMessage 、onmessage 可以直接通信
|
|
beginorApr 28, 2022 via Android
13
楼主的意思是一个 WinForm 程序,显示两个 webview ,可以通过 WinForm 程序进行通讯,WinForm 是可以和 webview 中的 js 相互调用的
|
|
KuroNekoFanApr 29, 2022
14
@snoopyhai 这个真的可以,亲测
|
|
leonkfdApr 29, 2022
15
可以试试将两个站点反向代理到同一个域名下,再用 postMessage 。
|
|
CmdhelpApr 29, 2022
16
都 exe 了 还有什么是不能共享的
|