postmessage

communication between two iframe children using postMessage

眉间皱痕 提交于 2019-12-05 12:30:59
问题 I have some embed code that users can put on their sites. It creates two children iframes on the page. I'd like to have those children be able to communicate. I'm using javascript's window.postMessage https://developer.mozilla.org/en-US/docs/DOM/window.postMessage Since the two iframe children can't communicate directly, I'm using the parent as a relay for messages. However the parent can be on a different domain since it's embeddable code. When all three (parent and two children) are on the

C# - WinFrm应用程序MessageBox自动关闭小实验

前提是你 提交于 2019-12-05 04:15:24
概述 在程序中MessageBox弹出的对话框,用于向用户展示消息,这是一个模式窗口,可阻止应用程序中的其他操作,直到用户将其关闭。但是有时候在自动化程序中,如果弹出对话框,程序将会中断,等待人工的干预,这是一个非常不好的交互体验,如果程序能够自动帮我们点击其中一个按钮,让对话框消失,该有多好。 原理 通过对话框的标题查找对话框,获取对话框的句柄,然后对话框发送指令。 涉及知识点 MessageBox 显示消息窗口(也称为对话框)向用户展示消息。这是一个模式窗口,可阻止应用程序中的其他操作,直到用户将其关闭。System.Windows.Forms.MessageBox可包含通知并指示用户的文本、按钮和符号。 Thread 创建和控制线程,设置其优先级并获取其状态。本例子主要创建一个线程,查找弹出的窗口。 WIN32 API 也就是Microsoft Windows 32位平台的应用程序编程接口。每一个服务,就是一个函数,用于和Windows进行交互。 MessageBoxButtons 是一个Enum,表示对话框上显示哪些按钮。 PostMessage 是Windows API(应用程序接口)中的一个常用函数,用于将一条消息放入到消息队列中。消息队列里的消息通过调用GetMessage和PeekMessage取得。 程序运行效果 核心代码 1 using System; 2

iframe cross domain messaging with jQuery postMessage plugin

大兔子大兔子 提交于 2019-12-05 03:14:09
I am trying to communicate between a child iframe and its parent using the following plugin: http://benalman.com/projects/jquery-postmessage-plugin/ I can follow the example and post a message from the child to the parent but not the other way and i really need to be able to communicate both ways. The code on the parent is as follows: var origin = document.location.protocol + '//' + document.location.host, src = origin + '/Custom/Ui/Baseline/html/iframe-data-cash.htm#' + encodeURIComponent(document.location.href); $(function () { var $holder = $('#iframe'), height, $iframe = $('<iframe src="'

实现两个窗口通信方法-postMessage

非 Y 不嫁゛ 提交于 2019-12-05 01:04:21
postMessage otherWindow:其他窗口的一个引用,比如iframe的contentWindow属性、执行window.open返回的窗口对象、或者是命名过或数值索引的window.frames。 message:将要发送到其他 window 的数据。它将会被结构化克隆算法序列化。这意味着你可以不受什么限制的将数据对象安全的传送给目标窗口而无需自己序列化。 targetOrigin:通过窗口的origin属性来指定哪些窗口能接收到消息事件,其值可以是字符串”“(表示无限制)或者一个URI。在发送消息的时候,如果目标窗口的协议、主机地址或端口这三者的任意一项不匹配targetOrigin提供的值,那么消息就不会被发送;只有三者完全匹配,消息才会被发送。这个机制用来控制消息可以发送到哪些窗口;例如,当用postMessage传送密码时,这个参数就显得尤为重要,必须保证它的值与这条包含密码的信息的预期接受者的orign属性完全一致,来防止密码被恶意的第三方截获。如果你明确的知道消息应该发送到哪个窗口,那么请始终提供一个有确切值的targetOrigin,而不是。不提供确切的目标将导致数据泄露到任何对数据感兴趣的恶意站点。 transfer:是一串和message 同时传递的 Transferable 对象. 这些对象的所有权将被转移给消息的接收方

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage'

早过忘川 提交于 2019-12-04 16:06:00
问题 i have following script Parent Page(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('#log').append("Received message: " + (e.data)); }, false); $('.photo-upload-btn').click(function(event) { event.preventDefault(); window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes"); }); The Child Page $.ajax({ type: 'post', url: url, data: { base64data: dataURL }, success: function(data) { window.opener.postMessage(data, "pair_pixel_filter.php");

Javascript post message event handler in ATL C++ BHO

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:30:18
On a webpage I have a button with JavaScript post message. In my BHO IE add-on I need an event listener for this message event. Any clue how this can be done? My OnDocumentComplete is as below. Can you give some more pointers where we can write code for handling this event. I want to make a REST API call from this message handler. TestScript.h: // TestScript.h : Declaration of the CTestScript #pragma once #include "resource.h" // main symbols #include "TestBHO_i.h" #include <mshtml.h> // DOM interfaces #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS

html5: postMessage解决跨域通信的问题

こ雲淡風輕ζ 提交于 2019-12-04 13:19:05
效果图 postmessage解析 HTML5提供了新型机制PostMessage实现安全的跨源通信. 语法 otherWindow.postMessage(message, targetOrigin, [transfer]); otherWindow: 其他窗口的一个引用, 比如IFRAME的contentWindow属性, 执行, window.open返回的窗口对象. message: 将要发送到其他窗口的数据. targetOrigin: 通过窗口的origin属性来指定哪些窗口能接收到消息事件, 其值可以是字符”*”(表示无限制)或者一个URL transfer: 是一串和message同时传递的Transferable对象. 这些对象的所有权将被转移给消息的接收方, 而发送一放将不再保有所有权. element.addEventListener(event,fn,useCaption ); 三个参数 event 事件 比如 click mouseenter mouseleave 回调函数 useCaption 用于描述是冒泡还是捕获。默认值是false,即冒泡传递。 当值为true,就是捕获传递。 实现方式 主界面 main.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta

User32 API custom PostMessage for automatisation

扶醉桌前 提交于 2019-12-04 09:45:04
问题 I want to automate a program called Spotify from C#, the best way (I think) to do this is by triggering fake keypresses. I want to program to pause playback, and I don't know enough about this stuff to find another way than keypresses. So I use Visual Studio's Spy++ to see what message Spotify gets when pressing the play button on my keyboard, I copy the data from that message into my Console Application and run it, when I run I can see the PostMessage in Spy++'s Message Logging, so this is

Communication between Chrome-app and a homepage with PostMessage

[亡魂溺海] 提交于 2019-12-04 08:43:39
I need to be able to send postMessage from a Chrome App through a webview to the homepage and back. I have established PostMessage from the Chrome App to the homepage, and the PostMessage is also catched by the homepage and a new one is send back, but this PostMessage reply is not caught by the Chrome App. I can see that it is possible on the Chrome-App API.: The guest will be able to send replies to the embedder by posting message to event.source on the message event it receives. So the problem is that i cannot get the Chrome App to catch the reply from the homepage, even though i am using

Can I do synchronous cross-domain communicating with window.postMessage?

空扰寡人 提交于 2019-12-04 07:45:33
I'm thinking of using window.postMessage directly for cross-domain communication. If I do: postMessage() from the parent frame Load an iframe window.addEventListener("message", callback, false); from the child iframe When will the messages I posted before loading the iframe be executed? Are they guaranteed to be executed at all? Are there timing guarantees? I would like to pass a parameter from the top frame that influences the initialization of the child frame. suknic The postMessage() function is asynchronous, meaning it will return immediately. So you can not do synchronous communication