【发布时间】:2011-01-05 11:02:35
【问题描述】:
我必须在 iframe 中调用回调方法才能将值返回给 opener。
我知道SqueezeBox 有“分配、打开、关闭”静态方法,但我不明白它是如何工作的,有人可以帮帮我吗?
【问题讨论】:
-
回答我自己。我已经用 SqueezeBox 功能解决了,谢谢。
标签: javascript static methods mootools
我必须在 iframe 中调用回调方法才能将值返回给 opener。
我知道SqueezeBox 有“分配、打开、关闭”静态方法,但我不明白它是如何工作的,有人可以帮帮我吗?
【问题讨论】:
标签: javascript static methods mootools
我对 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>
【讨论】: