开发者

Javascript call to close window

This has been bugging me for the last few hours now.

I am using the iframe version of LightFace modal windows :

http://davidwalsh.name/facebook-lightbox

The problem I am having is I cannot close the modal from inside the iframe itself (same domain)

Now I understand from hours of go开发者_如何学Pythonogle research it is possible with calls such as :

<a href="#" onclick="parent.$.nyroModalRemove(); return false;">Close Iframe</a>

parent.$.nyroModalRemove();

window.parent.$.prettyPhoto.close(); 

However I am unable to find the actual call variably needed in lightbox e.g blabla.close(); Ive tried Firebug and javascript debugger to no avail.

A working close buttom example can be seen here (this is located on the actual box modal) http://davidwalsh.name/dw-content/lightface.php clicking = "WalshFrame (LightFace.IFrame)"

Any Ideas?


Works for me with

parent.Ilight.close();

See the call:

document.id('iframe').addEvent('click',function() {
    Ilight = new LightFace.IFrame({ height:400, width:900, url: 'http://davidwalsh.name', title: 'David Walsh Blog!' }).addButton('Close', function() { this.close(); },'blue').open();
   });

"iframe" is the ID of the link WalshFrame (LightFace.IFrame).

So the variable you look for is defined there->Ilight


I'm doing something similar with Eric Martin's SimpleModal . The issue I was running into is that the $.modal.close()($.nyroModalRemove()) is not a global function. My solution was to create a global function on the parent page and call it from the IFRAME.

Parent Page

<script type="text/javascript">
    function closeModal() {
        $.nyroModalRemove();
    }
</script>

IFRAME Page

<a href="#" onclick="parent.closeModal(); return false;">Close Iframe</a>


In page 1:

<script type="text/javascript">  
<!-- destroy lightface   
function getElementsByClass(node,searchClass,tag) {   
var classElements = new Array();  
var els = node.getElementsByTagName(tag); // use "*" for all elements  
var elsLen = els.length;  
var pattern = new RegExp("\\b"+searchClass+"\\b");  
for (i = 0, j = 0; i < elsLen; i++) {  
 if ( pattern.test(els[i].className) ) {  
 classElements[j] = els[i];    
 j++;  
}  
}  
return classElements;  
}  
function closetest() {  
var el = getElementsByClass(document,'lightface','*');  
// alert(el.length);  
for (I=0;I<el.length; I++) { el[I].parentNode.removeChild(el[I]); }  
}  
//-->  
</script>

In iframe :

    <? echo"<br><a href=\"javascript:void(0)\" onclick=\"javascript:window.parent.telecharge('http://www.site.com/thumbnail/thimg/".$_FILE  S[userfile][name]."'); window.parent.closetest(); \">Pour publier cette image sur votre fil de messagerie, cliquez ici.</a>"; ?>

window.parent.closetest(); // 


I don't understand why you'd want to have the close-button inside the iframe. If you look closer at the example at david walsh's page, the close button is part of the modal, not inside the iframe. So I think the best solution would be to have some outer frame around the iframe in which to place the close-button (as in Walsh's example). With this solution its also easier to load pages into the iframe where you can't place a close button yourself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜