PDA

View Full Version : add time delay in on javascript popup



ianhaney
10-27-2016, 03:48 PM
Hi

I have a javascript popup that displays once per session, is it possible to add a time delay in as well so it pops up after 3 seconds as well as once per session, below is the coding I have so far



<script type="text/javascript">
$(document).ready(function() {

if (once_per_session==0)
loadpopunder()
else
{
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}



});
</script>

<script type="text/javascript">

//Pop-under window II- By JavaScript Kit
//Credit notice must stay intact for use
//Visit http://javascriptkit.com for this script

//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=1

///No editing beyond here required/////

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){

var id = '#dialog';

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
}

</script>


Thank you in advance

jscheuer1
10-27-2016, 04:39 PM
What do you mean? Every three seconds? After three seconds regardless of whether or not it has been seen this session? On load and then once again after 3 seconds if it hasn't been seen this session?

ianhaney
10-27-2016, 05:10 PM
What do you mean? Every three seconds? After three seconds regardless of whether or not it has been seen this session? On load and then once again after 3 seconds if it hasn't been seen this session?

sorry what I meant was have the popup show after 3 seconds of the page load and then not to show again so will show once

I have managed to get it sorted now with the following code



<script type="text/javascript">
$(document).ready(function() {

if (once_per_session==0)
var to_pop = setTimeout("loadpopunder()", 3000);
else
{
if (get_cookie('popunder')==''){
var to_pop = setTimeout("loadpopunder()", 3000);
document.cookie="popunder=yes"
}
}



});
</script>