4 Replies - 1444 Views - Last Post: 22 November 2007 - 02:40 AM

#1 lodiposh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-March 07

Timed Pop up window

Posted 14 November 2007 - 11:33 AM

Hi,

I'm a bit stuck on this project (see below). It's part of a bigger project but I snipped the trouble piece out and put it in it's own little temporary page for now until I work out the kinks. What I need is a pop up window with "toy tips" or funny sayings to occur at certain timed intervals while the user is viewing the main page. For now I have the timed interval set to occur every 30 secs while I'm testing it.

Also, I need the pop up window to stay open for enough time for the user to read the "tip" then to close itself before the new tip pops up. For testing I have that time set to 10 secs.

Problem is, I can get the tip to pop up but it does not close and another tip does not show up.

Help, feedback and/or clues as to what I'm doing wrong would be greatly appreciated!

Thanks!
Tammy

<html>
<head>
<title>Toy Store Tips</title>
<script language="Javascript" type="text/javascript"><!--

var tips = new Array(8)
tips[0] = "Expand your child\'s creative thinking with our artistic themed toys!"
tips[1] = "Play Doh may NOT be eaten under any circumstances!"
tips[2] = "Do not place toys near heat sources."
tips[3] = "Jacks should not be used as projectiles!"
tips[4] = "Always wear protective gear when using bikes and skateboards!"
tips[5] = "Doll\'s hair may lose original color if put in water!"
tips[6] = "May the force be with you!"
tips[7] = "Do not let children under 3 play with small toys!"


function displayTip(tips, width, height){
	var startDoc = "<html><head><title>Toy Tip</title></head>"
	startDoc += "<body bgcolor=lime text=black>"
	var endDoc = "</body></html>"
	var xPos = screen.availWidth > width ? screen.availWidth/2 - width/2 : 0
	var yPos = screen.availHeight>height ? screen.availHeight/2 - height/2: 0
	
	var features = "width=" + width + ", height=" + height
	features += ",screenX=" + xPos + ",screenY=" + yPos
	
	toyTip = window.open("", "TipWin", features)
	tipClose = setTimeout("toyTip.close()", 10000)	
	
	toyTip.document.writeln(startDoc, "<h2>Toy Tip</h2>")	
	toyTip.document.writeln(tips)
	toyTip.document.writeln(endDoc)
	
	
}
//-->
</script>
</head>
<body onload="displayTip(tips[Math.floor(Math.random()*8)], 200, 150),">

	<h2>Welcome to the Toy Store</h2>
	
<script language="Javascript" type="text/javascript"><!--
tipTimer = setInterval("displayTip(tips[Math.floor(Math.random()*8)], 200, 150)", "30000");
//-->
	
	
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Timed Pop up window

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Timed Pop up window

Posted 14 November 2007 - 11:44 AM

Try resetting your timer each time the pop up window closes. Also, eventually users will grow weary of pop up windows that continue to happen, just my opinion from a users perspective :)
Was This Post Helpful? 0
  • +
  • -

#3 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: Timed Pop up window

Posted 14 November 2007 - 09:21 PM

Hi,

As PshycoCoder said, it would probably be quite annoying to continually popup random windows.

Also, most people have popup-blockers. But anyway, this will work:

<html>
<head>
<title>Toy Store Tips</title>
<script language="Javascript" type="text/javascript"><!--

var tips = new Array(8)
tips[0] = "Expand your child\'s creative thinking with our artistic themed toys!"
tips[1] = "Play Doh may NOT be eaten under any circumstances!"
tips[2] = "Do not place toys near heat sources."
tips[3] = "Jacks should not be used as projectiles!" // What???
tips[4] = "Always wear protective gear when using bikes and skateboards!"
tips[5] = "Doll\'s hair may lose original color if put in water!"
tips[6] = "May the force be with you!"
tips[7] = "Do not let children under 3 play with small toys!"

function initialise() {
  // display a random tip at a random time between 15 and 30 seconds
  setTimeout("displayTip(tips[Math.floor(Math.random()*8)], 200, 150);", Math.random() * 15000+15000);

}

function displayTip(tips, width, height) {
	var startDoc = "<html><head><title>Toy Tip</title></head>";
	startDoc += "<body bgcolor=lime text=black>";
	var endDoc = "</body></html>";
	var xPos = screen.availWidth > width ? screen.availWidth/2 - width/2 : 0;
	var yPos = screen.availHeight>height ? screen.availHeight/2 - height/2: 0;
	
	var features = "width=" + width + ", height=" + height;
	features += ",screenX=" + xPos + ",screenY=" + yPos;
	
	toyTip = window.open("", "TipWin", features);
	tipClose = setTimeout("toyTip.close();initialise();", 10000); //close tooltip and initialise another after 10 seconds
	
	toyTip.document.writeln(startDoc, "<h2>Toy Tip</h2>");
	toyTip.document.writeln(tips);
	toyTip.document.writeln(endDoc);
}

//-->
</script>
</head>
<body onload="initialise();">

	<h2>Welcome to the Toy Store</h2>
	
<script language="Javascript" type="text/javascript"><!--
tipTimer = setInterval("displayTip(tips[Math.floor(Math.random()*8)], 200, 150)", "30000");
//-->
	
	
</body>
</html>



I've got it running now, and it's already annoying the hell out of me.

I suggest, that instead you use an in-frame element to display the messages, such as a DIV instead.

In fact, I strongly suggest you not to use popup windows. Really strongly.
Was This Post Helpful? 0
  • +
  • -

#4 lodiposh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-March 07

Re: Timed Pop up window

Posted 14 November 2007 - 11:59 PM

View PostNayana, on 14 Nov, 2007 - 09:21 PM, said:

I've got it running now, and it's already annoying the hell out of me.

I suggest, that instead you use an in-frame element to display the messages, such as a DIV instead.

In fact, I strongly suggest you not to use popup windows. Really strongly.


I hear you and I quite agree. I'm not actually using this in "real life" -- it's completely an assignment. I hate pop ups myself!

Thanks for the advice!
Tammy
Was This Post Helpful? 0
  • +
  • -

#5 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: Timed Pop up window

Posted 22 November 2007 - 02:40 AM

View Postlodiposh, on 14 Nov, 2007 - 11:59 PM, said:

I hear you and I quite agree. I'm not actually using this in "real life" -- it's completely an assignment. I hate pop ups myself!

Thanks for the advice!
Tammy


Right. Well, good luck for your assignment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1