[英]Change iframe src without refreshing parent page
我在ASP.NET網站中有一個頁面。 iframe位於Ajax更新面板中。
我需要從javascript更改iframe的src屬性,我可以這樣做。 問題在於,當src屬性更改時,父頁面將刷新。
我只需要框架導航,而不是父頁面。
HTML:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<iframe id="previewIframe" runat="server" Width="800px"></iframe>
</ContentTemplate>
</asp:UpdatePanel>
JavaScript的:
var frame = $("#previewIframe");
frame.setAttribute('src', "http://www.google.com");
HTML:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<iframe ClientIDMode="Static" id="previewIframe" src="" runat="server"></iframe>
</ContentTemplate>
</asp:UpdatePanel>
JavaScript的:
$("#previewIframe").attr('src', "http://www.google.com");
忘記了在ASP中元素ID不是神聖的,它們是前置的。 “MainContent_previewIframe”
一旦添加了ClientIDMode =“ Static”屬性,jquery就可以正確引用該元素。
還將jquery方法更新為$(“#previewIframe”)。attr('src','google.com'); -我混用了javascript和jquery。 我現在應該知道要堅持一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.