2012-03-02 2 views
8

게시물이 iframe에로드되는 Wordpress 사이트가 있습니다.iframe 내부에서 iframe을 닫는 방법?

<a class="trick" rel="<?php the_permalink() ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a> 

$ (문서) .ready (함수() {

$.ajaxSetup({cache:false}); 
    $(".trick").click(function(){ 
     var post_link = $(this).attr("rel"); 
     $("#frame").css("display","block"); 
     $("#frame").attr("url", post_link); 
     $("body").css("overflow","hidden"); 
    }); 

    });   </script> 
<iframe id="frame" frameborder="no" allowtransparency="true" width="100%" height="100%" scrolling="no" src=""></iframe> 

을 자,이로드를 닫는 방법 :

작동 코드입니다 iframe 내부의 iframe?

메인 페이지는 index.php (메인 워드 프레스 루프)이고 iframe의 내용은 머리글과 바닥 글이없는 single.php (단일 게시물)입니다.

감사합니다.


이 내가

<head> 

<script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script> 
    $(document).ready(function(){ 
     $("#close").click(function(){ 
      $('#frame', window.parent.document).remove(); 

      }); 

     }); 

    </script> 


</head> 

<body> 
<div id="container-single"> 
    <button id="close" >Close</button> 



    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <article <?php post_class('single') ?> id="post-<?php the_ID(); ?>"> 

      <h1 class="entry-title"><?php the_title(); ?></h1> 

      <div class="entry-content"> 

       <?php the_content(); ?> 

       <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?> 

       <?php the_tags('Tags: ', ', ', ''); ?> 

       <?php include (TEMPLATEPATH . '/_/inc/meta.php'); ?> 

      </div> 


     </article> 



    <?php endwhile; endif; ?> 

    </div> 

</body> 
+1

Iframe을 닫으시겠습니까? 무슨 소리 야? 내부 iframe 또는 무엇을 제거 하시겠습니까? –

+0

[iframe 내에서 iframe을 닫는 방법] 가능한 복제본 (http://stackoverflow.com/questions/6754935/how-to-close-an-iframe-within-iframe-itself) –

답변

17

iframe 내부로드 single.php에서 아래의 코드를 실행 single.php에있어 것입니다. 문맥으로 window 부모를 사용하여 iframe을 찾아 제거하거나 숨 깁니다.

//You can call hide() if you want to just hide it 
$('#iframe', window.parent.document).remove(); 
+0

해봤지만 작동하지 않습니다, 내 질문에 편집 된 내 single.php 내용을 볼 수 있습니다 ... –

+0

그냥 확인하십시오. 동일한 도메인에 iframe이 있습니까? – ShankarSangoli

+0

예, 물론입니다. iframe은 워드 프레스 게시물을로드합니다. –

9

사실 조금 트릭입니다.

는 당신이,

parent.closeIFrame(); 

까다로운되지하려는 상위 페이지는 어디에서 전화를 닫으려는 iframe이 내부

var closeIFrame = function() { 
    $('#iframeid').remove(); 
} 

에 함수를 확인?

+1

'window' 객체에 추가되지 않는 함수를 선언하면 다음과 같이해야합니다 :'var closeIFrame = function() {...}' – Jasper

+1

@ Jasper, thanks man. 지금 잠을 좀 자야 해 ...;) – Starx

1
// Inside the iframe  
frameElement.remove(); 
+0

이 방법이 효과적이지만 크로스 도메인이 아닙니다. –

0

이 문제는 Pinterest 's Pin It과 마찬가지로 북마크릿을 만들었습니다.

크로스 도메인에서 작동해야합니다. 나는 이것에 대한 답변을 게시 한

https://gist.github.com/kn0ll/1020251

:이 해결할 수

있는 유일한 방법은, GitHub의에이 예 다음은 iframe 내부의 페이지와 상위 페이지와 이벤트를 게시하여이었다 다른 스레드 : https://stackoverflow.com/a/43030280/3958617

희망이 있습니다.

관련 문제