推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
yazoox

两个 page 或者 webview,能够相互通讯么?

  •  
  •   yazoox · Apr 28, 2022 · 4328 views
    This topic created in 1660 days ago, the information mentioned may be changed or developed.

    现在有一个 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 ?

    16 replies  •  2022-04-29 10:57:25 +08:00
    ch2
    ch2
    Apr 28, 2022
    1
    跨域就不行
    ktqFDx9m2Bvfq3y4
    ktqFDx9m2Bvfq3y4
    Apr 28, 2022
    2
    @ch2
    这问题不大,都本地程序了。基本上都可以让 JS 与程序本身互调用的,基于此就可以让他们通讯。再不济你程序架一个本地 HTTP 让他们互通。
    IvanLi127
    IvanLi127
    Apr 28, 2022
    3
    postMessage ?
    LLaMA2
    LLaMA2
    Apr 28, 2022
    4
    在 windows 上做个 bridge ,然后 js bridge 完成功能
    3dwelcome
    3dwelcome
    Apr 28, 2022
    5
    如果是 electron 的 webview ,可以用 Node-API 作为中间桥梁来传参数,桥接方法有一大堆,随便写。
    yazoox
    yazoox
    OP
    Apr 28, 2022
    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 关系......
    snoopyhai
    snoopyhai
    Apr 28, 2022
    8
    @snoopyhai 才看到#6.。。。。额。。
    AV1
    AV1
    Apr 28, 2022 via Android
    10
    都 webview 了,用它所在的程序转发就好了。
    zlu1123
    zlu1123
    Apr 28, 2022
    11
    你的意思是同一个 app 中,两个 webview 通信嘛?可以用 js bridge
    auroraccc
    auroraccc
    Apr 28, 2022
    12
    你在 http://a.sample.com/componenta/index.html 里 window.open http://b.sample.com/componentb/index.html 就能拿到 b 窗口了,然后通过 postMessage 、onmessage 可以直接通信
    beginor
    beginor
    Apr 28, 2022 via Android
    13
    楼主的意思是一个 WinForm 程序,显示两个 webview ,可以通过 WinForm 程序进行通讯,WinForm 是可以和 webview 中的 js 相互调用的
    KuroNekoFan
    KuroNekoFan
    Apr 29, 2022
    14
    @snoopyhai 这个真的可以,亲测
    leonkfd
    leonkfd
    Apr 29, 2022
    15
    可以试试将两个站点反向代理到同一个域名下,再用 postMessage 。
    Cmdhelp
    Cmdhelp
    Apr 29, 2022
    16
    都 exe 了 还有什么是不能共享的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2102 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 04:44 · PVG 12:44 · LAX 20:44 · JFK 23:44
    ♥ Do have faith in what you're doing.