Javascript 停止在回发时重新加载iframe中的网页
当父页面回发时,如何防止Iframe中的网页重新加载? 下面是一个简单的.aspx页面。当我单击按钮1进行回发时,将重新加载源为blank.aspx的iframe。我怎样才能防止这种情况发生?代码如下Javascript 停止在回发时重新加载iframe中的网页,javascript,c#,asp.net,iframe,Javascript,C#,Asp.net,Iframe,当父页面回发时,如何防止Iframe中的网页重新加载? 下面是一个简单的.aspx页面。当我单击按钮1进行回发时,将重新加载源为blank.aspx的iframe。我怎样才能防止这种情况发生?代码如下 <div> This is an empty page with a button to open a modal window in an iframe <asp:Button ID="Button1" runat="server"
<div>
This is an empty page with a button to open a modal window in an iframe
<asp:Button ID="Button1" runat="server" Text="Postback" OnClick="Button1_Click" />
<asp:Label ID="lblPostback" runat="server" Text="Initial Load"></asp:Label>
<!-- Trigger/Open The Modal -->
<button id="myBtn" type="button">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
<iframe src="Site/Public/blank.aspx"></iframe>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function () {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
//When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</div>
这是一个空页面,带有一个按钮,用于在iframe中打开模式窗口
开放模态
&时代;
模态中的一些文本
//获取模态
var modal=document.getElementById('myModal');
//获取打开模式对话框的按钮
var btn=document.getElementById(“myBtn”);
//获取关闭模态的元素
var span=document.getElementsByClassName(“关闭”)[0];
//当用户单击该按钮时,打开模式对话框
btn.onclick=函数(){
modal.style.display=“块”;
}
//当用户单击(x)时,关闭模式对话框
span.onclick=函数(){
modal.style.display=“无”;
}
//当用户单击模式之外的任何位置时,将其关闭
window.onclick=函数(事件){
如果(event.target==模态){
modal.style.display=“无”;
}
}
您可以将回发过程中更改的元素封装在UpdatePanel中。如果iframe位于UpdatePanel之外,则在回发时不应重新加载。您可以将回发期间将更改的元素包装在UpdatePanel内。如果iframe在UpdatePanel之外,则在发回时不应重新加载它