将iframe中的javascript变量传递给父框架 [英] pass a javascript variable from an iframe to the parent frame
本文介绍了将iframe中的javascript变量传递给父框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我的iframe中有一个变量,如下所示:
So I have a variable in my iframe like so:
<script>
var zipphone = "<?= $phone ?>";
</script>
现在我想在加载iframe后将该变量传递给父框架。最简单的方法是什么?
Now I want to pass that variable to the parent frame after the iframe is loaded. What is the simplest way to do that?
推荐答案
如果页面都在同一个域上,你可以调用一个函数父窗口:
If the pages are both on the same domain, you could call a function of the parent window:
window.parent.zipPhoneCallback(zipphone);
在父窗口中,您可以定义如下函数:
In the parent window, you could define a function like this:
function zipPhoneCallback(zipphone) {
((console&&console.log)||alert)("zipphone = " + zipphone);
}
这篇关于将iframe中的javascript变量传递给父框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文