【问题标题】:How to fetch Response from Post Message如何从发布消息中获取响应
【发布时间】:2023-04-04 18:12:01
【问题描述】:

我一直在研究 trello api,所以我的问题是我必须在数据库中保存一个令牌。 回复在帖子中:

 window.opener.postMessage("token generated here ", "http://www.servername.com")

 1. how  to fetch token from post message.
 2.i have tried code from this link :http://stackoverflow.com/questions/3332532/how-can-i-do-cross-domain-postmessage. but is not working.
 3. https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage this link i also go through .

    snapshots step by step here is
    step 1: authentication with oath  :http://postimg.org/image/5cwazfvfv/
    step 2: when i press allow  button to get token  i recieve this window and here 
     url: http://postimg.org/image/f3y34m2dz/

【问题讨论】:

  • 需要更多信息!以便社区成员可以帮助您。你在使用 iframe 还是 popupwindow?
  • sr 我用快照更新了我的查询,请解决这个问题。

标签: javascript postmessage


【解决方案1】:

据我所知,postmessage 是异步的。因此,很难捕获哪个消息返回到哪个源父/窗口。我认为我们可以考虑以下两件事:

  1. 合理定义如何确定目标窗口(而不是“*”指示符)。就我而言,我们可以像这样临时使用:frameA.contentWindow.postMessage(msg, frameA.src). 但是,如果我们需要支持多个具有相同 href 的框架,我的解决方案仍然会遇到问题。
  2. 第二件事需要指出哪个目标页面将接收/处理来自框架的返回值。如上所述,我的解决方案是依赖事件对象的 origin 属性(例如用于 Chrome/Safari 浏览器。如果是其他版本/浏览器,我们需要使用相应的属性)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    相关资源
    最近更新 更多