Phi*_*ell 4 html javascript iframe load
我有一个PHP页面,其中包含一些iFrame,导致页面加载速度相当慢.一旦页面完全加载,我该如何才能加载那些iFrame?我假设我需要使用JavaScript,但我还没有找到有效的代码.
非常感谢.
编辑 - iFrame需要出现在PHP回声中.
这是代码:
<?php
while($i = mysql_fetch_array($e))
{
?>
<div class='dhtmlgoodies_question'>
<div style='float:left'><img src='../images/categories/<?=$i[Category]?>.png'></div>
<div class='name'><?=$i[Name]?></div>
<div class='location'><?=$i[Area]?></div>
</div>
<div class='dhtmlgoodies_answer'>
<div>
<div style='background-color:#FFF; margin-left:248px; padding:10px; color:#666'>
<?=$i[Address]?><br>
<?=$i[Area]?><br>
<a href='http://maps.google.com/maps?q=<?=$i[Postcode]?>'><?=$i[Postcode]?></a><
<p>
<?=$i[ContactName]?><br>
<?=$i[TelephoneNumber]?>
</div>
<p>
<a href='http://crbase.phil-howell.com/view.php?Employer=<?=$i[Employer]?>'>
Edit this entry
</a>
<br>
//HERE IS WHERE I WANT TO LOAD THE iFRAME
</p>
</div>
</div>
</div>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)
正如@Sudhir和@Richard所示,您可以通过延迟iframe内容的加载来解决此问题,而只需花费几行javascript行即可。
但是,有时将iframe元素放置到源代码中比在运行时创建元素更方便。好的,您也可以通过在运行时最初创建iframe指向about:blank并更改其源的元素来获得它:
<html>
<head>
<script>
function loadDeferredIframe() {
// this function will load the Google homepage into the iframe
var iframe = document.getElementById("my-deferred-iframe");
iframe.src = "./" // here goes your url
};
window.onload = loadDeferredIframe;
</script>
</head>
<body>
<p>some content</p>
<!-- the following iframe will be rendered with no content -->
<iframe id="my-deferred-iframe" src="about:blank" />
<p>some content</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
为@PhilHowell编辑:我希望这个主意现在更加清晰。
尝试在身体末端添加:
window.onload = function() {
var iframe = document.createElement('iframe');
iframe.style.display = "none";
iframe.src = your_iframe_source_url;
document.body.appendChild(iframe);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23812 次 |
| 最近记录: |