2013-02-02 1 views
0

실수로 colorbox를 닫지 않도록하여로드 된 iframe 내부에서 닫기 버튼을 표시하거나 숨길 수 있습니다.ColorBox - 닫는 것을 방지합니다.

나는 문서를 읽을 수 있지만 두 예제는 작동하지 않습니다

var originalClose = $.colorbox.close; 
$.colorbox.close = function(){ 
    var response; 
    if($('#cboxLoadedContent').find('form').length > 0){ 
     response = confirm('Do you want to close this window?'); 
     if(!response){ 
      return; // Do nothing. 
     } 
    } 
    originalClose(); 
}; 

또는

<!-- calling colorbox's close method from within an iframe: --> 
<a href='#' onclick='parent.$.colorbox.close(); return false;'>close this iframe</a> 

...을 colorbox 단지 닫히지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 콘솔에서

나는 참조 :

Uncaught TypeError: Cannot read property 'colorbox' of undefined 

감사합니다!

답변

0

jquery 라이브러리 뒤에 colorbox.cssjquery.colorbox.js을 포함해야합니다.

첫 번째 예는 colorbox close 함수를 재정의하고 두 번째 예는 colorbox를 닫는 것입니다. 내 예에서

$('#cboxLoadedContent').find('form') 

나는 form이없는, 그래서 form 선택을 제거합니다.

데모 : http://jsfiddle.net/BY3ZK/

Colorbox는 div하지 iframe을, 그래서 여기에서 parent을 제거 :

parent.$.colorbox.close(); 

데모 : http://jsfiddle.net/BY3ZK/1/

+0

사실, 정상적으로 작동하지만 iframe 내에서 작동하지 않습니다. – 3zzy

+0

같은 도메인의 @Nimbuz iframe? – webdeveloper

+0

아니요, 외부 도메인입니다. 다른 도메인의 콘텐츠가 iframe에로드된다는 의미입니다. – 3zzy

0

그것은해야한다 : yourElement이 colorbox를 포함하는 iframe 대응의 ID/선택기 것

parent.$('#yourElement').colorbox.close(); 

.

+0

라이트 박스가 포함 된 iframe? iframe을 포함하는 lightbox 및 iframe은 ID가 없습니다. – 3zzy

0

$ ('#의 cboxClose')를 사용하여 시도합니다. 풀다(); colorbox를 닫으려면

+0

항상 당신이 찾은 중복을 신고하는 것을 고려해 볼 수도있다. – bummi