window.parent.postMessage and window.location.hostname for t
window.parent.postMessage and window.location.hostname for the targetDomain
在子iframe中,我使用window.parent.postMessage('some msg', targetDomain)
向父消息。最初,targetDomain是一个硬编码的"字符串"(例如,http://my.childdomain.com
)。从那以后,我就被要求将targetDomain改为动态的,原因我们将在这里讨论。然后我尝试targetDomain作为http://'+window.location.hostname
,但有些事情是不对的。
我把alert(window.location.hostname)
放在前面,得到了正确的值,但window.parent.postMessage()
似乎不像window.location.hostname
。
suggesions吗?
哎呀!问题解决了。主要问题是我没有解析window.location.hostname来获得TLD。一旦我睡了一会儿,恢复了理智,我就意识到我的方式是错误的。也就是说,我需要告诉window。parent。postmessage消息的去向,而不是它的来源。是啊,我知道…
相关文章:
- 正在寻找比$(document).ready慢的$(window).load的替代方案
- 直接下载文件,而不是从window.open(url)
- 为什么JavaScript在for循环为3时向所有4发出警报
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 在Firefox for Android的onload事件中,window.innerWidth的值错误
- Mock window.document object for out-of-browser jQuery
- Phonegap 和 window.device 在 onDeviceReady for iOS7 中未定义
- Javascript onclick window.location for page anchors?
- 我可以在 for 循环中设置多个 window.setTimeout 事件吗?
- 将存储在数组中的 url 传递给 window.open in for loop - Javascript
- Authorization for window.location.href call in angular js
- AJAX and setInterval for window.location.hash
- window.open之后,可以't在Safari for Mac中打印
- 为什么不't Object.keys(window)或for(window中的k)返回Math
- DOM Exception 12 for window.postMessage
- window.parent.postMessage and window.location.hostname for t
- 如何在for循环中更改iframes或window.opener.location的src
- Inline javascript for window.open
- # for window.location.pathname
- JavaScript For循环显示window.location的最后一次迭代