postmessage

Testing postMessage with Jasmine async doesn't work

感情迁移 提交于 2019-12-04 03:17:56
I'm trying to use Jasmine 2.0 to write unit tests for some logic in an AngularJS app, but the logic is inside an event listener. From the controller: window.addEventListener('message', function(e) { if (e.data === "sendMessage()") { $scope.submit(); } }, false); And from the test file: describe("post message", function() { beforeEach(function(done) { var controller = createController(controllerParams); spyOn($scope, 'submit'); window.postMessage('sendMessage()', '*'); done(); }); it('should submit on a sent message', function (done) { expect($scope.submit).toHaveBeenCalled(); done(); }); });

communication between two iframe children using postMessage

非 Y 不嫁゛ 提交于 2019-12-04 01:45:52
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 same domain, it's pretty easy and I have this working with the security check checking the e.origin is

Can the PostMessage API be used to communicate with an Android WebView?

那年仲夏 提交于 2019-12-04 00:12:26
I usually use the HTML5 PostMessage API to communicate information from my iframed content to the parent frame. Recently I've had my content used inside an Android WebView (as far as I can tell this is the native-Android equivalent of an iframe). Is there a way for the native app to listen for PostMessage events that I send up to them? I'm aware that addJavascriptInterface exists, I'm just hoping that there's a way to reuse my existing PostMessage code without writing something new. I realize this question is old but I ran into it so I figured I would answer here. In short - I am finding that

Benefit of CORS over cross-domain messaging

故事扮演 提交于 2019-12-03 20:16:11
问题 CORS and cross-domain messaging look the same to me: they allow communication across domains. Are there any reasons to use one vs. the other? 回答1: CORS is for ajax requests or flash requests that flash wouldn't normally allow. For example, if there is no cross-domain policy for domain x, and you retrieve an mp3 file from there via flash for playback, flash will not allow you to read the id3 tags of the mp3 file. For ajax, you flat out cannot make the request if the target server doesn't have

前端笔记(1908-1911)

谁说我不能喝 提交于 2019-12-03 17:15:53
1、CORS 跨域携带 Cookie 发送请求 参考: https://segmentfault.com/a/1190000016032594 https://www.cnblogs.com/nuccch/p/7875189.html 需要从2个方面解决: 1)服务器端使用CROS协议解决跨域访问数据问题时,需要设置响应消息头 Access-Control-Allow-Credentials 值为“true”。同时,还需要设置响应消息头 Access-Control-Allow-Origin 值 为指定单一域名(注:不能为通配符“*”) 。 2)客户端需要设置Ajax请求属性withCredentials=true,让Ajax请求都带上Cookie。 若服务端将Access-Control-Allow-Origin设置为*,浏览器会报错The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include' 2、iframe sandbox属性 参考: https://developer.mozilla.org/zh-CN/docs/Web/HTML

js--window.postMessage

*爱你&永不变心* 提交于 2019-12-03 17:14:40
父页面想子页面发送消息: var iframe=document.getElementById('centerFormIframe_iframe').contentWindow; iframe.postMessage('full','*');    子页面向父页面发送消息: window.parent.postMessage('full','*');    监听: window.addEventListener('message',function(e){ if(e.data=='exit'){} })    来源: https://www.cnblogs.com/zhengziru/p/11804429.html

Why is html5 postMessage not working for me?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 15:45:50
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 get this message','http://localhost:3000'); console.log('posted'); }) And then, inside http:/

PostMessage with multiple functions or custom callbacks

只愿长相守 提交于 2019-12-03 12:03:26
问题 So far I've only seen tutorials for postmessage where one window sends a single kind of message, and the other window interprets the message in only a single way. What if I want to have many different kinds of interactions between windows, can postmessage handle that? Is that going against the grain of what postmessage is supposed to do? For example, what if I wanted to be able to send custom callbacks back and forth, etc? 回答1: There are a couple of ways to pass a multi-part message on to a

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

血红的双手。 提交于 2019-12-03 11:55:56
This question already has answers here : addEventListener overwrites other event actions? (2 answers) 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 noticed when I added a console.log to the processMessage function to debug communication from the iframe, it was picking up a lot

javascript postMessage not working

余生长醉 提交于 2019-12-03 11:53:24
问题 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>