2017-04-26 94 views
0

如何防止iframe中的網頁在父頁執行回發時重新加載? 下面是一個簡單的.aspx頁面。當我單擊Button1時,會執行回發,將重新加載具有blank.aspx作爲其源的iframe。我怎樣才能防止這種情況發生?代碼如下。停止在回傳中重新加載iframe中的網頁

 <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" /> 
    &nbsp;<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">&times;</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> 

回答

0

您可以在UpdatePanel中包裝將在回發期間更改的元素。提供iframe然後在UpdatePanel之外,它回發時不應該重新加載。

+0

謝謝你的工作。 – enski