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

Discussion in 'HTML' started by cx, Aug 10, 2007.

  1. cx

    cx Guest

    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>
    cx, Aug 10, 2007
    #1
    1. Advertising

  2. cx

    BootNic Guest

    cx <> wrote:
    news::

    > 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>

    --
    BootNic Friday, August 10, 2007 9:56 AM

    I had a monumental idea this morning, but I didn't like it.
    *Samuel Goldwyn*
    BootNic, Aug 10, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page