How to access variables in an iframe?(Opera,JavaScript)

C

cx

I want to acess a variable in the iframe, the following code runs well
in Firefox and IE, but fails in Opera. Can I modify the code to meet
opera's standard?

a.htm:
<iframe id=q src="b.htm"></iframe>
<script>
var i;
var l=document.getElementById('q');
alert(l.kkk);
</script>

b.htm:
<script>
var kkk=1;
</script>
 
B

BootNic

I want to acess a variable in the iframe, the following code runs well
in Firefox and IE, but fails in Opera. Can I modify the code to meet
opera's standard?

a.htm:
<iframe id=q src="b.htm"></iframe>
<script>
var i;
var l=document.getElementById('q');
alert(l.kkk);
</script>

b.htm:
<script>
var kkk=1;
</script>

<script type="text/javascript">
var l=document.getElementById('q');
l.onload=function(){alert(l.contentWindow.kkk)}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top