Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2009, 05:24 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to start a counter timer when iframe created

Hi, I have a simple html page which will dynamically creates an iframe (using javascript) when clicks on a hyperlink. My problem is I want to write some text message (e.g: Hello World) inside the iframe with a delay time of 5 seconds after the iframe being created. It will be good if the time control can be done within the iframe and not from the parent, as the message and delay mechanism happen only after iframe created. Below is some code snippet.

HTML Code:
<html>
<head>
<script type="text/javascript">
function createFrame() {

   var tempIFrame=document.createElement('iframe');
   tempIFrame.setAttribute('id','frameID');
   tempIFrame.style.border='1px solid';
   tempIFrame.style.width='250px';
   tempIFrame.style.height='100px';
   tempIFrame.style.visibility="visible";
   var IFrameObj = document.body.appendChild(tempIFrame);

   if (IFrameObj.contentDocument) {
      IFrameDoc = IFrameObj.contentDocument;
   } else if (IFrameObj.contentWindow) {
      IFrameDoc = IFrameObj.contentWindow.document;
   } else if (IFrameObj.document) {
      IFrameDoc = IFrameObj.document;
   } else {
      alert('Problem creating iframe');
   }

   return false;
}

</script>
</head>
<body>
<a onclick="createFrame();" href="#">Click Me</a>
</body>
</html>
I am thinking of using the setTimeout() function in the iframe but have no idea how to dynamically create it. Sample code is most welcome and hope to get some answers from this forum. Thank you.
 
Old June 23rd, 2009, 05:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well if you set the source of the iframe then the page you provide can have this functionality. Otherwise, once you have the iframe's document, you should be able to document.write any HTML you need.
__________________
Joe
http://joe.fawcett.name/




Similar Threads
Thread Thread Starter Forum Replies Last Post
hit counter alfredogirosi ASP.NET 3.5 Basics 0 April 13th, 2009 07:37 PM
values from one iframe to another iframe URGENT raaj Beginning PHP 2 February 27th, 2007 12:19 PM
Counter tp194 Javascript 1 September 2nd, 2004 08:02 AM
the counter is not incremented harag XSLT 2 November 10th, 2003 11:54 AM
counter Adam H-W Classic ASP Basics 15 August 15th, 2003 11:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.