阻止加载隐藏的iframe的内容 [英] Prevent loading the content of a hidden iframe
问题描述
我有很多隐藏的< div>
标签,我打电话给(显示:无)
当我想加载一个jQuery模式。
这些< div>
标记中的每一个都包含一个< iframe>
,它会调用另一个页面。
I have many hidden <div>
tags, with (display: none)
, that I call upon when I want to load a jQuery modal.
Each of these <div>
tags contain an <iframe>
which calls a different page.
为了不让我的页面加载缓慢,我想知道是否有办法阻止< iframe>
从加载页面,直到我在模态中调用< div>
?
In order to not make my page load painfully slowly, I am wondering if there is a way to prevent the <iframe>
from loading the page, until I call the <div>
in the modal?
推荐答案
你可以通过在iframe的html中给出空src并稍后通过jquery / javascript分配src来加载html之后加载iframe。
You can load the iframes after html being rendered by giving empty src in html of iframe and later assigning src by jquery / javascript.
Html
<iframe id="iframe1" ></iframe>
Javascript,iframe可以加载某些动作,例如点击按钮
document.getElementById('iframe1').src="/default.aspx";
kern3l 说,我们可以在iframe中添加数据属性来保存src而不是硬编码。
As kern3l said, we can add data attribute in iframe for holding src instead of hard coding.
Html
<iframe id="iframe1" data-frameSrc="/default.aspx"></iframe>
Javascript
ifrmame1 = $('#iframe1')
ifrmam1.src = ifrmam1.data("frameSrc");
您还可以在jquery中创建一个新帧并分配src,这将加载带有空白帧的页面。
You can also make a new frame in jquery and assign src, this will load the page with blank frame.
$('<iframe>', {
src: '/default.aspx',
id: 'myFrame',
frameborder: 0,
scrolling: 'no'
}).appendTo('#parentDivId');
OR
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);
这篇关于阻止加载隐藏的iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!