我必须在 iframe 中调用回调方法才能将值返回给 opener。
I know 挤压盒 http://digitarald.de/project/squeezebox/有“分配、打开、关闭”静态方法,但我不明白它是如何工作的,有人可以帮助我吗?
我对 SqueezeBox 不太了解,但我在 iframe 通信方面做了一些工作。除非您的 iFrame 和 opener 位于同一域中,否则您无法从一个到另一个进行调用。
为了解决这个问题,我所做的就是写入 URL 的哈希值。然后,开启者可以读取该值并弄清楚该怎么做。
例如,
<iframe name="my-frame" id="my_frame" src="http://www.somewhere.com" width="540" height="1000" border="0" style="overflow:hidden; border: none;">
<script type="text/javascript">window.location.hash = 'close';</script>
</iframe>
<script type="text/javascript">
// Function to look for a token in the url hash
var tokenValue = function(){
var hash = document.location.hash;
return (hash && hash.length > 1) ? hash.substring(1, hash.length) : null;
};
// Function to set the token and notify the user when it is found in the url hash.
var checkForToken = function(){
if (tokenValue()) {
alert(tokenValue());
$clear(periodical);
}
};
// Start a periodical that will check for
var periodical = checkForToken.periodical(100);
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)