...

View Full Version : Delay loading a page



tacbob
02-23-2009, 03:36 PM
Is it possible to delay the loading of an IFrame for several seconds using JS?

Thanks

ohgod
02-23-2009, 09:09 PM
<script type="text/javascript">
Event.observe(window,'load',function(){
window.setTimeout(alert('alert 100ms after page load',100);
});
</script>

tacbob
02-24-2009, 01:38 PM
Thank you OhGod.

Not had chance to try it yet.
I presume that because there is no IFrame ID in the code, then the script sits in the cell??

Thanks

itsallkizza
02-24-2009, 08:10 PM
An elaboration of what ohgod's suggestion:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<style type="text/css">
</style>
<script type="text/javascript">
// <![CDATA[

function addEventHandler(to_element,event,handler)
{
if (typeof(handler)=="string") handler = Function(handler);
var f = event.substr(0,2);
var e = (f=="on"||f=="On"||f=="ON"||f=="oN") ? event.substr(2) : event;
to_element.addEventListener ? to_element.addEventListener(event,handler,false) : to_element.attachEvent("on"+event,handler);
}

function loadIframe()
{
document.getElementById("my_iframe").src = "http://www.google.com";
}

addEventHandler(window,"load",function(){
setTimeout("loadIframe()",2000);
});

// ]]>
</script>
</head>
<body>

<iframe id="my_iframe" src="" scrolling="false"></iframe>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum