2013-02-26 71 views
0

我正在使用來自http://www.ericmmartin.com/projects/simplemodal/的simplemodal。Simplemodal - iframe將不會關閉

我遇到的問題是,一旦它打開,我無法關閉iframe。

<script type="text/javascript"> 

// Route Which Page 

$.modal('<iframe src="<?= $src ?>" height="230" width="550" style="border:0">', { 
    closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>", 
    containerCss:{ 
     backgroundColor:"#eee", 
     borderColor:"#ddd", 
     height:230, 
     padding:0, 
     width:550 
    }, 
    overlayClose:false 
}); 

    /* When #btnClose is clicked, close the modal */  
    $('#disagree').on("click", function(event){ 
     parent.$.modal.close(); 
    }); 

</script> 

彈出和工作很好,只是不能彈出關閉!我已經使用所有谷歌的想法不會關閉。我可以將它關閉,然後閃爍,然後打開第二個iframe。

我用下面的代碼以關閉:

/* When #btnClose is clicked, close the modal */  
$('#disagree').on("click", function(event){ 
    $.modal.close(); 
}); 


/* When #btnClose is clicked, close the modal */  
$('#disagree').on("click", function(event){ 
    parent.$.modal.close(); 
}); 

<a href="#" title="Close" class="modal-close simplemodal-close">x</a> 

的實際模式設置:

closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>", 

工作正常,但我需要的操作按鈕來關閉它們是在iframe內部哪些正在加載。

任何想法或幫助將是驚人的!

回答

0

從着眼於簡單的演示彈出,然後在看的密切聯繫所使用的點擊事件數據,我發現這一點:

功能(B){b.preventDefault();一.close()}

這些數據是從靠近AHREF <a class="modalCloseImg simplemodal-close" title="Close" id="modalId"></a>從這個鏈接Basic Modal Dialog

你能不那麼試試這個:

$('#disagree').on("click", function(event) 
    { 
    $('#modalId').trigger('click'); 
    //OR: 
    $('.modalCloseImg').trigger('click'); 
    }); 

「modalId」僅僅是我給上述ahref鏈接的一個Id。或者你可以這樣做:$('#IdOfiFrame').remove();

2

活動添加到您的鏈接中的iframe

$('.modal-close').click(function() { 
     parent.$.modal.close(); 
    }); 
+0

這個工作對我來說,這個代碼放置在iframe頁面。不需要其他的js電話。 – Mikeys4u 2016-12-28 12:51:25