Page 1 of 1

how to set time for popup window

Posted: Sat Feb 05, 2011 12:00 am
by mehran
hi,
plz help me
i want to genrate the popup on database time,
like use set 1 hour it gerate the popup after one hour,
or he set the time in mints the poup show on time
plz help me in the setting of time,
how could i retriew time from the db and check it
tnx in advance

Re: how to set time for popup window

Posted: Fri Feb 11, 2011 8:57 pm
by mecha_godzilla
Hi,

You could try this code:

Code: Select all

function start_page_timer() {

	min = 60 * 1; /* 60 minutes */
	sec = 0 + 0;
	count_down_page_timer();
	
}

function count_down_page_timer() {

	sec--;      
	
	if (sec == -1) {
		sec = 59;
		min--;
	}
	
	if (min == 0 && sec == 0) {
		alert("Something is supposed to happen at this point!");
	} else {
		down = setTimeout("count_down_page_timer()", 1000);
	}

}
You then just need to call the start_page_timer() function in the onLoad="" section of your <body> tag. You can replace the alert() with a pop-up window, redirect to a new page or whatever else you want to do. Note that the timer will be reset every time the page is reloaded (or a new page is loaded) but if you want to compare it against a timestamp in the database you'll need to store that information in PHP somewhere and rewrite the JavaScript function to reduce the start time - this would be if you only wanted someone to have access to your site for a specific amount of time.

Bear in mind that with this kind of script someone can easily disable JavaScript support in their browsers - if you need to make sure someone is logged-out after a certain amount of time you'll need to use a $_SESSION value in PHP to store the original timestamp and then test it against the current timestamp each time a page is loaded - if you need code to do this please let me know.

HTH,

Mecha Godzilla