我有很多隐藏的<div>
标签,带有 (display: none)
,当我想要加载 jQuery 模式时我会调用它。
其中每一个<div>
标签包含 <iframe>
它调用不同的页面。
为了不让我的页面加载缓慢缓慢,我想知道是否有办法阻止 <iframe>
从加载页面,直到我调用 <div>
在模态中?
最佳答案
您可以在 html 渲染后加载 iframe,方法是在 iframe 的 html 中提供空 src,然后通过 jquery/javascript 分配 src。
HTML
<iframe id="iframe1" ></iframe>
Javascript、iframe 可以在某些操作(如按钮单击)上加载
document.getElementById('iframe1').src="/default.aspx";
如kern3l也就是说,我们可以在iframe中添加data属性来保存src,而不是硬编码。
HTML
<iframe id="iframe1" data-frameSrc="/default.aspx"></iframe>
Javascript
ifrmame1 = $('#iframe1')
ifrmam1.src = ifrmam1.data("frameSrc");
您还可以在 jquery 中创建一个新框架并分配 src,这将加载带有空白框架的页面。
$('<iframe>', {
src: '/default.aspx',
id: 'myFrame',
frameborder: 0,
scrolling: 'no'
}).appendTo('#parentDivId');
或者
var iframe = document.createElement('iframe');
iframe.frameBorder=0;
iframe.width="300px";
iframe.height="250px";
iframe.id="myFrame";
iframe.setAttribute("src", '/default.aspx');
document.getElementById("parentDivId").appendChild(iframe);
关于jquery - 防止加载隐藏 iframe 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14868252/