【发布时间】:2019-04-23 10:17:18
【问题描述】:
我在一个顶部有标签的网站中有一个页面。单击时每个选项卡显示不同的部分。每个部分都有多个 iframe。
我的问题是,当加载带有标签的页面时,加载速度很慢,因为它一次加载所有标签中的所有 iframe。
我正在寻找一种仅加载可见 iframe 的方法。有没有办法阻止 iframe 的加载,例如在单击选项卡时设置它的源,或者更简单的方法让它在可见 = true 时加载?
搜索博客和网站,我只发现为什么使用 iframe 和 iframe 的替代品不好。就我而言,使用 iframe 非常实用。
这是一个 HTML 选项卡的示例,它位于 div 标签内:
<div class="single" id="Company_Options">
<fieldset style="margin-top:-10px; border: 1.5px solid #00659c; height:auto;">
<legend style="color:#00659c;font-weight:bold;font-size:20px;" id="Company_Title" runat="server"></legend>
<table style="width:100%; margin-top:-10px; margin-bottom:-30px;">
<tr>
<td style="width:50%;">
<fieldset>
<legend style="color:#00659c;font-weight:bold;font-size:15px;" id="Company_Country_Title" runat="server"></legend>
<iframe id="iframeCountryList" frameborder="0" scrolling="auto" width="100%" height="100%" src="CountriesList.aspx" style=""></iframe>
</fieldset>
</td>
<td style="width:50%;">
<fieldset>
<legend style="color:#00659c;font-weight:bold;font-size:15px;" id="Company_Currencies_Title" runat="server"></legend>
<iframe id="iframeCurrencyList" frameborder="0" scrolling="auto" width="100%" height="100%" src="CurrenciesList.aspx" style=""></iframe>
</fieldset>
</td>
</tr>
<tr>
<td style="width:50%;">
<fieldset>
<legend style="color:#00659c;font-weight:bold;font-size:15px;" id="Company_Departments_Title" runat="server"></legend>
<iframe id="iframeDepartmentList" frameborder="0" scrolling="auto" width="100%" height="100%" src="DepartmentList.aspx" style=""></iframe>
</fieldset>
</td>
<td style="width:50%;">
<fieldset>
<legend style="color:#00659c;font-weight:bold;font-size:15px;" id="Company_Divisions_Title" runat="server"></legend>
<iframe id="iframeDivisionList" frameborder="0" scrolling="auto" width="100%" height="100%" src="DivisionList.aspx" style=""></iframe>
</fieldset>
</td>
</tr>
</table>
</fieldset>
</div>
标签设置如下:
Company_Options.Visible = false;
iframe 的内容仍在加载。
我需要类似这样的伪代码:
iframeCountryList.Render = false;
iframeCurrencyList.Render = false;
iframeDivisionList.Render = false;
iframeDepartmentList.Render = false;
Company_Options.Visible = false;
关于如何阻止 iframe 呈现的任何想法,无论是在 C# 中的代码后面还是在客户端 javascript 中?谢谢!
【问题讨论】:
标签: javascript c# html asp.net iframe