postmessage

javascript postMessage not working

时光总嘲笑我的痴心妄想 提交于 2019-12-03 02:31:02
I don't know what to do. I tried several sample codes from different sources, I tried them in different browsers (from Chrome 9 to FF 4), and still nothing seems to be working with the "postMessage" function. JS console is giving me nothing, not a single error, still nothing is happening : the frames don't want to communicate. At all. And this isn't even cross-domain : both frames are from my domain. Here is a sample code from the last try : Parent frame : <iframe src="IFRAME_URL"></iframe> <script> window.addEventListener( "message", function (e) { if(e.origin !== 'DOMAIN'){ return; } alert(e

How to properly use postMessage to do cross-domain messaging with html5 and modern browsers ? I still get errors

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm sure something is wrong here but I can't quite put a finger on it... The example here behaves just fine with no notices or errors on the console, so it means my browser supports cross domain messaging with html5 (of course it does, it's Chrome 14..). My code does more or less the following: A script loaded in WebsiteA.com created an iframe and appends it to WebsiteA.com's document. The frame appended will contain WebsiteB.com and when it's loaded, it must send a message to it's parent, WebsiteA.com, to tell it that WebsiteB.com is ready

Sending Keystroke to another application using WinAPI

笑着哭i 提交于 2019-12-03 00:43:01
I have to control another application by sending keystrokes to it like CTRL S or CTRL SHIFT C or CTRL F . I've tried a lot of things, but I can't get it working. So I'm trying to get this right on a simpler case. This successfully sends Hey to the notepad: procedure TForm1.Button1Click(Sender: TObject); var notepad, edit: HWND; begin notepad := FindWindow('notepad', nil); edit := FindWindowEx(notepad, FindWindow('Edit', nil), nil, nil); SendMessage(edit, WM_CHAR, dword('H'), 0); SendMessage(edit, WM_CHAR, dword('e'), 0); SendMessage(edit, WM_CHAR, dword('y'), 0); end; And this successfully

MFC PostMessage

匿名 (未验证) 提交于 2019-12-03 00:30:01
afx_msg LRESULT OnUpdateStatic(WPARAM wParam, LPARAM lParam); BEGIN_MESSAGE_MAP(CUserDlg, CBCGPDialog) ON_MESSAGE(WM_UPDATE_STATIC, &CUserDlg::OnUpdateStatic) END_MESSAGE_MAP() LRESULT CUserDlg::OnUpdateStatic(WPARAM wParam, LPARAM lParam) { if (wParam == 0) { GetDlgItem(IDC_STATIC_MESSAGE)->SetWindowText(_T("Hello Linux")); } else { GetDlgItem(IDC_STATIC_MESSAGE)->SetWindowText(_T("Hello Windows")); } } UINT CUserDlg::ThreadFunction(LPVOID pParam) { CUserDlg *pDlg = (CUserDlg *)pParam; while (TRUE) { ::PostMessage(pDlg->m_hWnd, WM_UPDATE_STATIC, 0, 0); Sleep(1000); ::PostMessage(pDlg->m_hWnd,

跨域请求的几种方式

匿名 (未验证) 提交于 2019-12-03 00:26:01
浏览器的同源策略,凡是发送请求的url的 协议、域名、端口号三者之间任意一者与当前页面地址不同的极为跨域。 JSONP 通过动态插入一个script标签。由于浏览器对script标签没有同源限制。 实际中,jsonp通常用来获取json数据,这时前后端约定一个callback。 缺点: - 无法发送post请求 - 确定jsonp的请求是否失败并不容易,大多数框架的实现都是结合超时开判断的。 var url= 'http://localhost:8080/WorkGroupManagment/open/getGroupById" +"?id=1&callback=?' ; $.ajax({ url:url, dataType: 'jsonp' , processData: false , type: 'get' , //jsonp 类型下只能使用GET,不能用POST,这里不写默认为GET success: function (data) { alert(data.name); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); }}); url

跨域

房东的猫 提交于 2019-12-02 22:23:58
本文主要涉及三种跨域方法:JSONP、CORS、postMessage。 Q:为什么会出现跨域问题? A:出于浏览器的同源策略限制,浏览器会拒绝跨域请求。 *注:严格的说,浏览器并不是拒绝所有的跨域请求,实际上拒绝的是跨域的读操作。浏览器的同源限制策略是这样执行的: 通常浏览器允许进行跨域写操作(Cross-origin writes),如链接,重定向; 通常浏览器允许跨域资源嵌入(Cross-origin embedding),如 img、script 标签; 通常浏览器不允许跨域读操作(Cross-origin reads)。* Q:什么情况才算作跨域? A:非同源请求,均为跨域。名词解释: 同源 —— 如果两个页面拥有相同的协议(protocol),端口(port)和主机(host),那么这两个页面就属于同一个源(origin)。 img01 Q:为什么有跨域需求? A:场景 —— 工程服务化后,不同职责的服务分散在不同的工程中,往往这些工程的域名是不同的,但一个需求可能需要对应到多个服务,这时便需要调用不同服务的接口,因此会出现跨域。 如何实现跨域 通常,最常用的跨域方式有以下三种:JSONP、CORS、postMessage。 JSONP 单纯地为了实现跨域请求而创造的一个 trick。 【实现原理】 虽然因为同源策略的影响

C# MessageBox自动关闭

匿名 (未验证) 提交于 2019-12-02 22:10:10
本文以一个简单的小例子,介绍如何让MessageBox弹出的对话框,在几秒钟内自动关闭。特别是一些第三方插件(如:dll)弹出的对话框,最为适用。本文仅供学习分享使用,如有不足之处,还请指正。 概述 在程序中MessageBox弹出的对话框,用于向用户展示消息,这是一个模式窗口,可阻止应用程序中的其他操作,直到用户将其关闭。但是有时候在自动化程序中,如果弹出对话框,程序将会中断,等待人工的干预,这是一个非常不好的交互体验,如果程序能够自动帮我们点击其中一个按钮,让对话框消失,该有多好。 原理 通过对话框的 标题 查找对话框,获取对话框的 句柄 ,然后对话框发送指令。 涉及知识点 WIN32 API 也就是Microsoft Windows 32位平台的应用程序编程接口。每一个服务,就是一个函数,用于和Windows进行交互。 MessageBoxButtons 是一个Enum,表示对话框上显示哪些按钮。 PostMessage 是Windows API(应用程序接口)中的一个常用函数,用于将一条消息放入到消息队列中。消息队列里的消息通过调用GetMessage和PeekMessage取得。 示例截图如下: 关键代码 核心代码如下: 1 using System; 2 using System.Collections.Generic; 3 using System.Drawing;

HTML(六)HTML iframe 使用postMessage方法进行跨文档消息传递

匿名 (未验证) 提交于 2019-12-02 20:32:16
HTML内联框架元素 <iframe> 表示嵌套的浏览上下文,有效地将另一个HTML页面嵌入到当前页面中。 <iframe id="inlineFrameExample" title="Inline Frame Example" width="300" height="200" src="https://www.openstreetmap.org/export/embed.html?bbox=-0.004017949104309083%2C51.47612752641776%2C0.00030577182769775396%2C51.478569861898606&layer=mapnik"> </iframe> 【src】 嵌套页面的URL地址。使用遵守同源策略的 ' about:blank ' 来嵌套空白页。 同源政策由 Netscape 公司引入浏览器。目前,所有浏览器都实行这个政策。 协议相同: http https ftp 指的是协议 域名相同: www.baidu.com www.taobao.com 指的是域名 端口相同: 默认是80端口 8800 8899这个指的是端口 https://www.baidu.com:80(80是默认的可以省略) 举例来说,)。它的同源情况如下。 http://www.example.com/dir2/other.html:同源

跨域问题的解决与具体实现

我的未来我决定 提交于 2019-12-02 12:20:31
为什么会有跨域 跨域指的是当两个url的协议,域名,端口三者有一个不同,就会发送跨域。之所以会有跨域,是因为浏览器的同源策略限制。 跨域的解决方法 jsonp jsonp简单来说就是通过在html中插入一个script标签,利用其src属性来发起请求,通过在src中为callback添加对应的回调函数来达到对响应数据进行处理的目的 如下例子 发起请求的客户端 <!DOCTYPE html> < html lang = " en " > < head > < meta charset = " UTF-8 " > < meta name = " viewport " content = " width=device-width, initial-scale=1.0 " > < meta http-equiv = " X-UA-Compatible " content = " ie=edge " > < title > Document </ title > </ head > < body > < script > let sendJSONP = function ( url , callbackName ) { // 新建script标签 let script = document . createElement ( "script" ) ; //

iframe 页面嵌套

两盒软妹~` 提交于 2019-12-01 08:30:35
由于目前项目基础界面,业务逻辑一样,只是细微有所差别。因而使用iframe来进行定制化处理。 如何来区分不同需求不同页面呢? 最初是想通过 url 携带参数来进行区分,但是随着需求变多,定制化也越来越细微,若是再使用url进行处理,有些太累赘了。因而思量再三,开始使用 postMessage 进行处理。 postMessage 满足跨域(不同域名间通信) message 可以传递对象 targetOrigin 可以指定哪些窗口接收信息 代码展示及描述 父向子传递信息 parent.html html <iframe id="iframe" src="http://DOMAIN1.com/child.html"></iframe> js const iframe = document.getElementByID('iframe') const sendChildData = { style: { btn_color: '#fff' } } // 默认只要是嵌套的页面都可以接收信息 * iframe.contentWindow.postMessage(sendChildData, '*') child.html html <button id="btn">提交</button> js window.addEventListener('message', function (e) {