我有一個aspx頁面,我加載到通過jQuery對話框顯示的iframe。該頁面有一個Cancel按鈕,用於調用成功關閉JQuery對話框的「CloseMe」腳本。該頁面還有一個保存按鈕,可以回傳。數據保存後,我想關閉對話框。Javascript錯誤關閉asp.net窗體內部JQuery對話框iframe後回發
我試着註冊一個啓動腳本,它調用document.ready上的「CloseMe」函數。當我這樣做時,代碼開始在JQuery中拋出JavaScript錯誤,這沒有意義。像「數組未定義」和「功能未定義」和「日期未定義」。編輯:當它擊中「window.parent。$ ...(close)語句時,它會執行此操作。請注意該行之前的警報,它正確地報告了iframe的ID
我使用相同的」CloseMe 「從功能的取消按鈕,一切工作正常
編輯:忽略調試器的所有25個左右的錯誤後,對話框DOES接近
這裏是打開的對話框中的javascript:
function jQueryShowiFrame(url, title, reloadOnClose) {
$('<iframe id="modalIframeId" allowtransparency="true" frameborder="0" src="' + url + '" />').load(function() {
var width = $("#modalIframeId").contents().width();
var height = $("#modalIframeId").contents().height();
var paddingWidth = parseInt($("#modalIframeId").css("padding-left"), 10) + parseInt($("#modalIframeId").css("padding-right"), 10);
// the sequence of these steps is important
$("#modalIframeId").dialog("option", "width", (width + paddingWidth) + 'px');
this.style.width = width + 'px';
this.style.height = height + 'px';
$("#modalIframeId").dialog("option", "position", "center");
})
.dialog({
title: title,
modal: true,
close: function (ev, ui) {
$(this).dialog('destroy').remove();
if (reloadOnClose) {
location.reload();
}
},
open: function (ev, ui) {
//alert('x');
}
});
}
以下是頁面標記:
<asp:Button ID="btnSave" runat="server" CssClass="BasicButton" Text="Save" />
<button type="button" id="btnClose" onclick="closeMe()" >Cancel</button>
<script type="text/javascript">
function closeMe() {
alert(window.frameElement.id);
window.parent.$('#' + window.frameElement.id).dialog('close');
}
</script>
這裏是保存按鈕點擊後面的代碼:
Dim scr As String = "$(document).ready(function() { closeMe(); });"
ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), Guid.NewGuid.ToString, scr, True)
可能是您在創建之前訪問了'frameElement.id'。但在關閉按鈕'CloseMe'工作正常,因爲'frameElement'創建。 –
我想到了。但是當我把「alert(window.frameElement.id);」聲明,它以正確的ID作出響應。 – Cary