开发者

How can I quote iframe's javascript variable in parent's window

开发者 https://www.devze.com 2023-01-28 02:16 出处:网络
In A.html I open an iframe with B.html in it. in B.html,I write js: <script type=\"javascript\"> var b=0;

In A.html I open an iframe with B.html in it.

in B.html,I write js:

<script type="javascript">
    var b=0;

   function test(){
       alert(b);
       return b;
   }
</script>

so in A.html I want quote the variable b in B.html I write this:

<script type="javascript">
    var a;

    a=window.frames[0].b;
    alert(a);
</script>

but the resault is "undefined"; however,I quote the function test in A.html

<开发者_运维知识库;script type="javascript">
    var a;

    a=window.frames[0]. test();
    alert(a);
</script>

both the variable a and b could alert correctly

so why the second quote method could not work?


This works for me.

Which browser do you use? Are you sure that the document inside the frame is already loaded when you access the property?

0

精彩评论

暂无评论...
验证码 换一张
取 消