postmessage

html5 Postmessage解决跨域问题

大憨熊 提交于 2019-11-27 14:35:28
在 Cross-document messaging 中使用 postMessage 和 onmessage 为了实现不同域之间的通信,需要在操作系统的 hosts 文件添加两个域名,进行模拟。 清单 3. hosts 文件中添加两个不同的域名 127.0.0.1 parent.com 127.0.0.1 child.com 在父网页中通过 iframe 嵌入子页面,并在 JavaScript 代码中调用 postMessage 方法发送数据到子窗口。 清单 4. 父页面中嵌入子页面,调用 postMessage 方法发送数据 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test Cross-domain communication using HTML5</title> <script type="text/JavaScript"> function sendIt(){ // 通过 postMessage 向子窗口发送数据 } </script> </head> <body> <!-- 通过 iframe 嵌入子页面 --> <iframe src="http://child.com:8080/TestHTML5/other-domain.html

详解5种跨域方式及其原理

杀马特。学长 韩版系。学妹 提交于 2019-11-27 14:33:13
同源定义 如果两个页面拥有相同的协议(protocol),端口(如果指定),和主机,那么这两个页面就属于同一个源(origin)。 以下是同源检测的示例 URL 结果 原因 http://store.company.com/dir2/other.html Success http://store.company.com/dir/inner/another.html Success https://store.company.com/secure.html Failure 协议不同 http://store.company.com:81/dir/etc.html Failure 端口不同 http://news.company.com/dir/other.html Failure 主机不同 1.jsonp script标签是不受同源策略影响的,它可以引入来自任何地方的js文件。 而jsonp的原理就是,在客户端和服务端定义一个函数,当客户端发起一个请求时,服务端返回一段javascript代码,其中调用了在客户端定义的函数,并将相应的数据作为参数传入该函数。 function jsonp_cb ( data ) { console . log ( data ); } function ajax (){ var url = "http://xx.com/test.php?jsonp

Web Worker

半城伤御伤魂 提交于 2019-11-27 10:51:29
写在前面 众所周知, JavaScript是单线程的 ,JS和UI更新共享同一个进程的部分原因是它们之间互访频繁,但由于共享同一个进程也就会造成js代码在运行的时候用户点击界面元素而没有任何响应这样的情况,这么糟糕的用户体验HTML5怎么会不修订了,这样Web Worker诞生了。 简介 Web Worker进程加载的js运行的时候不仅不会影响浏览器UI,而且也不会影响其它Web Worker进程加载的JS代码。由于Web Worker进程加载的js运行的时候不会影响浏览器UI,也就说明Web Worker中加载的js不能修改用户界面,而每个Web Worker都有自己的全局运行环境,因为它加载的js不能修改用户界面,所以它能操作的对象主要只包括以下几个部分 一个浏览器对象,只包含四个属性:appName,appVersion,userAgent,platform 一个location对象(和window里的一样,但是里面所有的属性是只读的) 一个self对象指向全局Web Worker线程对象 一个importScripts()方法使Web Worker能够加载外部js文件 所有的ECMAScript对象 XMLHttpRequest构造器 setTimeout()和setInterval()方法 WebWorker擅长之处 这里先特意讲一个importScript方法

postMessage still broken on IE11?

ε祈祈猫儿з 提交于 2019-11-27 07:06:52
It seems that window.postMessage is still broken on IE 11 when the message is between a window and a child popup/tab with window.open when it's sent from different domains [or same domain in some case, c.f. update 16/01] There was similar issues with IE 8/9/10 but this feature was flagged as 'supported' in IE 11 from 'partially supported' in IE 10 There is an example of the code that works on chrome/ff but not IE: The opener (jsfiddle) : $(document).ready(function() { $('#log').append('listening...'); window.addEventListener("message", function(e){ $('#log').append("Received message: " + JSON

Sending right ALT+C with PostMessage

孤人 提交于 2019-11-27 06:30:04
问题 I trying to send in my application RIGHT ALT + C . I tried do it following: PostMessage(hWindow, WM_KEYDOWN, (IntPtr)0x0043, (IntPtr)0x0012); Delay(1000); PostMessage(hWindow, WM_KEYUP, (IntPtr)0x0043, (IntPtr)0x0012); and PostMessage(hWindow, WM_KEYDOWN, (IntPtr)0x0043, (IntPtr)0x0001); Delay(1000); PostMessage(hWindow, WM_KEYUP, (IntPtr)0x0043, (IntPtr)0x0001); but it doesn't correctly. How should I used it? 回答1: Yes, it's possible using PostMessage. I used program Spy++ (it's inside Visual

Failed to execute 'postMessage' on 'DOMWindow': target/origin mismatch http vs https

て烟熏妆下的殇ゞ 提交于 2019-11-27 03:45:46
问题 I apologize up front as I'm very confused by my problem. I'm really in a bind because this is causing a problem on my production site. I have a javascript player on my site which plays through song lists which can be hosted on youtube, soundcloud or vimeo. Yesterday I noticed this error which generally arises anytime you try to load a new song through "skipping" with the player buttons. This error just started in the last day or two. I am not seeing anything new in the youtube api release

window.postMessage

守給你的承諾、 提交于 2019-11-27 01:18:32
HTML5 跨域通信 API - window.postMessage 参考 MDN - Window.postMessage() Syntax otherWindow .postMessage(message, targetOrigin, [transfer]) message 你要发送的信息(字符串和对象都可以) targetOrigin 你要发送信息的目标域名 transfer 可选参数,具体啥意思还没做深入了解,也暂时都还没用到过。 MDN 介绍的 window.postMessage() 是针对在一个页面使用 window.open() 动态打开新的页面而进行的跨域通信,非常详细,Demo 也很实用,但是对我而言貌似还欠缺什么东西。 注意, 在实现跨域通信是,必须首先先获得其他域的window窗体对象 Tips 在 var targetPage = window.open('http://target.com') 打开新页面之后需要等到 http://target.com 页面加载完成之后才能进行 postMessage 跨域通信,但是在跨域的情况下我们是无法对 targetPage 进行 onload 事件监听的,所以这里只能做 延迟 setTimeout 或者 定时 setInterval 处理。 同样的,在页面内嵌入 iframe 页面的情况下

渐进式web应用开发---Service Worker 与页面通信(七)

一个人想着一个人 提交于 2019-11-26 23:49:07
/*--> */ /*--> */ 阅读目录 一:页面窗口向 service worker 通信 二:service worker 向所有打开的窗口页面通信 三:service worker 向特定的窗口通信 四:学习 MessageChannel 消息通道 五:窗口之间的通信 六:从sync事件向页面传递消息 回到顶部 一:页面窗口向 service worker 通信 Service Worker 没有直接操作页面DOM的权限。但是可以通过postMessage方法和web页面进行通信。让页面操作DOM。并且这种操作是双向的。 页面向service worker 发送消息,首先我们要获取当前控制页面的 service worker。可以使用 navigator.serviceWorker.controller 来获取这个service worker. 之后我们就可以使用 service worker 中的 postMessage() 方法,该方法接收的第一个参数为消息本身,该参数可以是任何值,可以是js对象,字符串、对象、数组、布尔型等。 比如如下代码是 页面向service worker 发送了一条简单对象的消息: navigator.serviceWorker.controller.postMessage({ 'userName': 'kongzhi', 'age': 31

Is cross-origin postMessage broken in IE10?

≯℡__Kan透↙ 提交于 2019-11-26 19:33:26
I'm trying to make a trivial postMessage example work... in IE10 between windows/tabs (vs. iframes) across origins Remove any one of these conditions, and things work fine :-) But as far as I can tell, between-window postMessage only appears to work in IE10 when both windows share an origin. (Well, in fact -- and weirdly -- the behavior is slightly more permissive than that: two different origins that share a host seem to work, too). Is this a documented bug? Any workarounds or other advice? (Note: This question touches on the issues, but its answer is about IE8 and IE9 -- not 10) More details

Is cross-origin postMessage broken in IE10?

让人想犯罪 __ 提交于 2019-11-26 08:58:27
问题 I\'m trying to make a trivial postMessage example work... in IE10 between windows/tabs (vs. iframes) across origins Remove any one of these conditions, and things work fine :-) But as far as I can tell, between-window postMessage only appears to work in IE10 when both windows share an origin. (Well, in fact -- and weirdly -- the behavior is slightly more permissive than that: two different origins that share a host seem to work, too). Is this a documented bug? Any workarounds or other advice?