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

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

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