开发者

Controlling the top parent window from iframe with jquery or javascript

开发者 https://www.devze.com 2023-01-15 22:31 出处:网络
I have a page on my site which has a blank text field. Next to this is a button which opens up an iframe (using colorbox). This iframe shows a list of files - next to each file is a button which puts

I have a page on my site which has a blank text field. Next to this is a button which opens up an iframe (using colorbox). This iframe shows a list of files - next to each file is a button which puts the filenam开发者_StackOverflow社区e in to the text field in the parent window by calling the function below:

function returnImage(file){

  $('#input_text_id', window.parent.document).val(file);
  parent.$.fn.colorbox.close();

}

This works great, however a problem arises when I click a folder in the iframe. This causes the page in the iframe to load a different page of files. After this, the function no longer works.

Is there anyway that I can use jquery to access the very top parent page and control that? So we would have something like:

function returnImage(file){

  $('#input_text_id', theoriginalwindow.document).val(file);
  parent.$.fn.colorbox.close();

 }

Hope this makes sense, if you require more info, please let me know.

Thanks


In top window:

<script>
   function returnImage(file, doc){
       $('#input_text_id', doc).val(file);
       $.fn.colorbox.close();
   }
</script>

From iframe:

<script>
    top.returnImage(file, document); // top is top parent window.
</script>


Use top.

0

精彩评论

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