Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delay loading a page

    Is it possible to delay the loading of an IFrame for several seconds using JS?

    Thanks

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    Code:
    <script type="text/javascript">
    		Event.observe(window,'load',function(){
    		window.setTimeout(alert('alert 100ms after page load',100);
    		});
    </script>

  • #3
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    An elaboration of what ohgod's suggestion:

    Code:
    <!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>
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •