cowboy / jquery-postmessage

jQuery postMessage: Cross-domain scripting goodness
http://benalman.com/projects/jquery-postmessage-plugin/
GNU General Public License v2.0
356 stars 133 forks source link

Example doesn't work #9

Closed tianxu0836 closed 11 years ago

tianxu0836 commented 12 years ago

Parent: iframe src="http://localhost/WebFlowUI/ZoomInOut2.aspx"

js code- $(function () { $.receiveMessage(function (e) { alert(e.data); }, 'http://localhost/WebFlowUI/'); });

Child: var parent_url = "file:///C:/HomeWeb/test.html"; $.postMessage("ZoomIn", parent_url, parent);

I just found this plugin, I'm not able to make it work with the example code. In my test html, I have a iframe. In iframe I have a zoom in button. I need the parent receive msg from that button.

tianxu0836 commented 12 years ago

Aha! I got it. This way works:

Child:

var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined); $.postMessage("ZoomIn", '*', target);

Parent: $.receiveMessage(function (e) { alert(e.data); });

barneycarroll commented 11 years ago

Fancy closing this, @tianxu0836 ?