postmessage

HTML5 Web Worker的使用

ぐ巨炮叔叔 提交于 2019-12-21 11:59:50
来源: feng_013 的博客 Web Workers 是 HTML5 提供的一个javascript多线程解决方案,我们可以将一些大计算量的代码交由web Worker运行而不冻结用户界面。 一:如何使用Worker Web Worker的基本原理就是在当前javascript的主线程中,使用Worker类加载一个javascript文件来开辟一个新的线程,起到互不阻塞执行的效果,并且提供主线程和新线程之间数据交换的接口:postMessage,onmessage。 那么如何使用呢,我们看一个例子: 1 2 3 4 5 //worker.js onmessage = function (evt){ var d = evt.data; //通过evt.data获得发送来的数据 postMessage( d ); //将获取到的数据发送会主线程 } HTML页面:test.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <!DOCTYPE HTML> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <script type= "text/javascript" > //WEB页主线程 var worker = new

SendMessage vs PostMessage + WaitForSingleObject

我的梦境 提交于 2019-12-21 09:16:09
问题 I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject. Thoughts? 回答1: SendMessage() may be denied, if you call it from within the context of a COM call, where the COM object lives in an STA (calls are dispatched through the message pump). PostMessage() is not restricted to adhere to COM apartment rules. Also, PostMessage() puts the message on the end of the window's message queue. SendMessage() bypasses

PostMessage from a sandboxed iFrame to the main window, origin is always null

血红的双手。 提交于 2019-12-21 07:26:28
问题 There's something I don't get about the event origin with javascript postMessage event. Here is my main page: <html> <body> <h1>Test</h1> <h2>Outside</h2> <iframe src="iframe-include.html" width="100%" height="100" sandbox="allow-scripts"></iframe> <script type="text/javascript"> window.addEventListener('message', function (event) { console.log(event); }, false); </script> </body> </html> And my iFrame content <html> <body> <h3>Inside</h3> <script type="text/javascript"> var counter = 1,

Why is html5 postMessage not working for me?

假装没事ソ 提交于 2019-12-21 05:09:37
问题 I use a few lines of javascript to create an iframe element, and then I'd like to send it a message, like this: function loadiframe (callback) { var body = document.getElementsByTagName('body')[0]; var iframe = document.createElement('iframe'); iframe.id = 'iframe'; iframe.seamless = 'seamless'; iframe.src = 'http://localhost:3000/iframe.html'; body.appendChild(iframe); callback(); } loadiframe(function() { cpframe = document.getElementById('iframe').contentWindow; cpframe.postMessage('please

Does window.addEventListener('message') overwrite other listeners? [duplicate]

大兔子大兔子 提交于 2019-12-21 04:01:21
问题 This question already has answers here : addEventListener overwrites other event actions? (2 answers) Closed 5 years ago . I've got some code that communicates with an iframe using .postMessage() , meaning it needs to add a listener on message to receive communication from the iframe. I'm using the usual code for that: window.addEventListener('message', processMessage, false); This code runs on a client's page that has a bunch of other stuff on it: Analytics, social buttons, etc. etc. I

MFC data forwarding to main thread via PostMessage

扶醉桌前 提交于 2019-12-21 02:35:38
问题 I have a C++/MFC application I need to restructure. The app used to process most of the data on the main thread, therefore blocking the input, and now I want to change it so, that all GUI updates are done through PostMessage. Unfortunately, I can't seem to find a good source on how to achieve this goal. Right now I'm thinking of creating a priority queue, protected with critical section, a worker thread (while(true)) that processes this queue, and PostMessage mechanism that sends pointers to

postMessage between cross-domain windows not working in IE10 (it works for frames)

一曲冷凌霜 提交于 2019-12-19 07:13:08
问题 I followed this tutorial http://davidwalsh.name/window-postmessage, and created cross domain messaging scripts which works in Chrome and Firefox but not in IE 10. Could anyone give me some hits on how to modify it for IE 8+? At one server(eg: 192.168.15.223)--receiver <script> //listener window.addEventListener('message',function(event) { if(event.origin !== 'http://120.0.0.211') return; document.getElementById('cc').innerHTML = event.data; },false); window.attachEvent('onmessage',function

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned

旧巷老猫 提交于 2019-12-18 10:47:17
问题 I'm trying to call parent.postMessage(obj, 'whatever'); from within an iframe and I'm getting this error: Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned. 回答1: It turns out the object I passed had methods, which is why the error message said An object could not be cloned . In order to fix this, you can do the following: obj = JSON.parse(JSON.stringify(obj)); parent.postMessage(obj, 'whatever'); 来源: https://stackoverflow.com/questions/42376464

cross site iframe postMessage from child to parent

与世无争的帅哥 提交于 2019-12-18 03:35:49
问题 I found this samplefrom SO while browsing for my problem, but I want to know exactly how to use it in my scenario. I have an iframe which is from another domain, and I want to detect when the iframe url is changed from one to another page in that other domain. So, what I was thinking is to have something like this when the 2nd page in the iframe is opened: <script type="text/javascript"> $(document).ready(function() { parent.postMessage("Second Page"); } </script> That's all I need, I just

postMessage still broken on IE11?

偶尔善良 提交于 2019-12-17 08:59:09
问题 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(