Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

pass a javascript variable from an iframe to the parent frame

So I have a variable in my iframe like so:

 <script>
var zipphone = "<?= $phone ?>";
 </script>

Now I want to pass that variable to the parent frame after the iframe is loaded. What is the simplest way to do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...