标签: postmessage

来自同一域的两个 iframe 之间使用 postMessage 进行通信

I have two iframes from the same domain, which are hosted in document from another domain. The problem is these iframes cannot communicate with each other through postMessage. I cant even access the DOM of iframe1 from iframe2 even though they belong to same domain. Is there any solution ????

I used following options to refer the required iframe.

parent.frame[x]
Run Code Online (Sandbox Code Playgroud)

I tried following lines to access DOM of iframes

parent.frame[x].contentWindow returns null,

parent.frame[x].document.getElementsByTagName("body") returns null
Run Code Online (Sandbox Code Playgroud)

Update:

I guess my question …

html iframe postmessage same-origin-policy

4
推荐指数
1
解决办法
6497
查看次数

用于自动化的 User32 API 自定义 PostMessage

我想用 C# 自动化一个名为 Spotify 的程序,(我认为)最好的方法是触发假按键。我想编程来暂停播放,但我对这个东西了解不够,无法找到按键以外的其他方法。因此,我使用 Visual Studio 的 Spy++ 来查看按下键盘上的播放按钮时 Spotify 收到的消息,我将该消息中的数据复制到我的控制台应用程序中并运行它,当我运行时,我可以在 Spy++ 的消息日志记录中看到 PostMessage,所以这是有效的,但它不会暂停/播放我的音乐。我想这是因为我还必须发送另一个带有另一个目的地的 PostMessage,但是我怎么知道还要发送什么?

留言电话:

MessageHelper.PostMessage((int)hwndSpotify, 0x100, 0x000000B3, 0x01000001);
Run Code Online (Sandbox Code Playgroud)

我希望有人熟悉这一点并可以帮助我。

.net c# windows postmessage

4
推荐指数
1
解决办法
3284
查看次数

我的表单永远不会收到已发布的自定义消息

我正在使用PostMessage从其他单元发送消息到主表单,如下所示:

procedure notify(var Message: TMessage); message 1;
Run Code Online (Sandbox Code Playgroud)

在程序中,信息显示如下WParam:

procedure TForm1.notify(var Message: TMessage);
begin
  Case (Message.WParam) of
    1: memo1.Lines.Add('task started');
    2: memo1.Lines.Add('in progress');
  end;
end;
Run Code Online (Sandbox Code Playgroud)

在另一个单元中,我发送这样的消息:

PostMessage(Handle, 1, 2, variable_info);
Run Code Online (Sandbox Code Playgroud)

首先,什么是消息ID?我将它替换为1,因为它的类型是基数,我应该使用什么呢?我的消息永远不会收到,因为Message.WParam它永远不会等于1或2.我的代码有什么问题?


我编辑了这样的代码:unit1

 const
 WM_MY_MESSAGE = WM_USER + 0;
Run Code Online (Sandbox Code Playgroud)

在代码中我添加了这样的东西:

 PostMessage(Handle,WM_MY_MESSAGE, 1,value_sent);
Run Code Online (Sandbox Code Playgroud)

TFormUnit:

  private
  procedure notify(var Message :TMessage); message WM_MY_MESSAGE;

  procedure TFormMain.notify(var Message: TMessage);
  begin
  Case (Message.WParam)of // which is 1
   1:
  //------------------------------------------
  begin
   memo1.Lines.Add('task started');
Run Code Online (Sandbox Code Playgroud)

通常在PostMessage(Handle,WM_MY_MESSAGE,1,value_sent)时; 执行我应该启动消息任务,但它是相同的错误,没有任何反应!

delphi postmessage

4
推荐指数
1
解决办法
717
查看次数

将WM_COMMAND发送到TMenuItem

在我的Delphi表单的OnShow方法中,我确定在打开表单后必须自动打开一个对话框 - 我应该可以通过模拟menuitem上的点击来完成此操作.

但是,调用menuitem.Click会在主窗体打开之前显示对话框 - 这不是我想要的.

我希望这应该做我想要的,但我找不到要通过"wparam"将点击发送到我的menuitem的参数.

PostMessage(handle, WM_COMMAND, wparam, 0)
Run Code Online (Sandbox Code Playgroud)

MSDN文档WM_COMMAND谈IDM_*标识符,但如何出现在德尔福?

delphi winapi postmessage tmenuitem

3
推荐指数
1
解决办法
2843
查看次数

关于javascript postmessage到本地磁盘上的父HTML iframe

我正在开发一个涉及在iframe中托管网页的项目,而托管父iframe位于本地磁盘上的HTML文件中,比如c:\; 而内部托管的iframe在某些服务器上.这两个网页需要彼此进行邮寄消息.

父内容iframe(在本地磁盘上)将消息发送到内部框架没有问题,因为它知道内部iframe的域;

但是当内部iframe需要postmessage回到父iframe时,它需要提供本地磁盘上的父iframe的域.

我在内部HTML中尝试了以下内容,将postmessage邮寄到其父IFrame,该IFrame位于本地磁盘上:

*var messageToSend = {
                        jsonrpc: "2.0",
                        result: [result]
                    };
window.parent.postMessage(JSON.stringify(messageToSend), "file://");*
Run Code Online (Sandbox Code Playgroud)

// window.parent IFrame是本地磁盘上的HTML文件

但是当我尝试使用"file:"作为postmessage中的域回到父iframe时,我收到一个"无效参数"错误.

有人可以帮忙吗?"本地磁盘html"的域应该是什么?任何提示将受到高度赞赏.

干杯

javascript postmessage file local

3
推荐指数
1
解决办法
4271
查看次数

PostMessage()消息是否在Windows中按顺序出现?

一般的问题是,如果我从一个单独的工作线程向Windows消息泵发送几条消息,它们会按照我发送的顺序出现在目的地吗?即..

::PostMessage(m_hUsers, WM_BULKPROCESS, 0, 0);
// ... some processing here ...
::PostMessage(m_hUsers, WM_BULKDONE, 0, 0);
Run Code Online (Sandbox Code Playgroud)

m_hUsers是一个窗口的句柄(HWND)我正在从我的工作线程发送消息.因此,WM_BULKPROCESS将始终首先显示在窗口中(因此由该对话框类中的处理程序处理),或者它们是否可能出现故障,即WM_BULKDONE在WM_BULKPROCESS之前得到处理,即使它是最后发送的?

windows mfc postmessage

3
推荐指数
1
解决办法
1432
查看次数

安全使用window.postMessage,是"if(event.source!== window){return;}"好吗?

我想window.addEventListener("message",myOnmessageCallback,false)用来接收来自我window自己的消息.(这就是说我不想让这个myOnmessageCallback函数容易接收来自其他一些来源的恶意消息(我想这可能是其他框架,browserWindows,制表符,父和iframe,对吧?).

因此,我想,如果这避免触及任何东西而不是我window自己.

function myOnmessageCallback(event)
{
  if(event.orign !== window)
  {
  // I assume the message is from not this window here, therefore ignore it.
  return;
  }

  //do some useful stuff with the message received (only from window)
}

这似乎是一种减少myOnmessageCallback回调的好方法,只是处理通过window.postMessage()网页本身发送的消息吗?

PS:对于那些认为我为什么希望这种postMessage onmessage能力降低的人.我希望有一种方法可以在Javascript执行队列中放置一些内容,允许在两者之间处理UI内容.我会使用经典window.setTimeout但这个时间最短,我不想浪费时间.

javascript security postmessage message-queue

3
推荐指数
1
解决办法
3431
查看次数

WinApi消息循环,Postmessage就像SendMessage一样

你好有人回答我为什么当我运行这个程序时,MessageBoxes的顺序是1,2,4,3而不是1,2,3,4.在我看来,程序应该在启动WM_USER + 11之前结束执行WM_PAINT程序,为什么不呢?

// Win32Project6.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Win32Project6.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);


DWORD thread(LPVOID lpdwThreadParam);

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi postmessage getmessage

3
推荐指数
1
解决办法
1188
查看次数

自定义事件和postMessage之间的区别

为了将消息发送到另一个文档(比方说一个iframe),您可以使用两者postMessagecreateEvent函数.假设这个:

var event = document.createEvent('CustomEvent');
event.initCustomEvent("message", true, true, 'Hello world');
iframe.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果两种方法都有效,那么使用postMessage和之间有什么区别customEvent

javascript html5 postmessage custom-events

3
推荐指数
1
解决办法
1057
查看次数

来自iFrame的postMessage不再适用于CRM 2016内部部署

我一直在使用postMessage从iFrame到CRM进行一段时间的通信.它在CRM 2011和CRM 2015中有效,但它不再适用于CRM 2016.

iFrame javascript代码:

    var pass_data = {
        'refresh': 'false',
        'expand': 'true'
    };        
    window.parent.postMessage(JSON.stringify(pass_data), 'crm url');
Run Code Online (Sandbox Code Playgroud)

CRM javascript:

function setListener() {

  if (window.XMLHttpRequest) {
    //for browsers other than ie
    window.addEventListener("message", receivePostMessage, false);

  } else {
    //ie
    window.attachEvent('onmessage',receivePostMessage);

  }
} 

function receivePostMessage(event) {
   //do something with event.data
   var pass_data = JSON.parse(event.data);
   alert(pass_data);
  }
Run Code Online (Sandbox Code Playgroud)

setListener()在页面加载时被调用,我已经确认它正被调用.我已经尝试使用"*"作为目标原点,它仍然无法正常工作.

有谁知道这在CRM 2016中是否仍然是一个可行的选择?

javascript iframe postmessage dynamics-crm dynamics-crm-2016

3
推荐指数
1
解决办法
1217
查看次数