dtvgo28624 2016-01-08 07:12
浏览 45
已采纳

从iframe调用函数

I am uploading files using a hidden iframe as a target...from inside this iframe I want to run a function that's on my main page.

In my target iframe.php I have

<script>

upload_completed(<?php echo $numerolinha ?>); 
    </script>

but I get from firebug:

ReferenceError: loading_linha_21 is not defined
parent.upload_completed();</script>

If I run upload_completed(loading_linha_21); on my main page it runs ok so I'm guessing the command to run the function on the parent page isn't working... help!

I also tried :

window.top.upload_completed(<?php echo $numerolinha ?>); 

window.upload_completed(<?php echo $numerolinha ?>);

my functions :

 <script >
 function upload_started(id){

  $(id).css("display","block");
 }
 function upload_completed(id){
 $(id).css("display","none");
 }


 </script>
  • 写回答

2条回答 默认 最新

  • dtdd25012 2016-01-08 09:29
    关注

    The best guess i can give you is that the jQuery function requires the id to be #name_of_id, so when you call the function from the iframe like so:

    parent.upload_completed('#<?php echo $numerolinha ?>');
    

    or you can change your function to do this:

    function upload_started(id){
        $( '#' + id).css("display","block");
    }
    
    function upload_completed( id ) {
        $( '#' + id ).css("display","none");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?