Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Merging Javascript Popup with Javavscript countdown?

Posted on 2012-04-06
3
Medium Priority
?
267 Views
Last Modified: 2012-04-23
Hi All,

I currently have a javascript popup that appears when the user is approaching the end of their session and asks if they would like to renew the session. At the moment the popup just says that the session will time out in 50 seconds. What I would really like is for the seconds to count down until the session expires.

The Javascript popup is also not very pretty so if there is a more elegant way of doing it that won't get blacked by popup blockers then feel free.

This is the current code:

<?php
  $cookie_life = 60;
  session_set_cookie_params(60);
  session_name('test_session');    
  session_start();    
  
  session_regenerate_id(true);
?>

<script type="text/javascript">

var xmlhttp_session;
function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp_session=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp_session=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp_session.onreadystatechange=cfunc;
xmlhttp_session.open("GET",url,true);
xmlhttp_session.send();
}

function extend_session()
{
loadXMLDoc("session_extend.php",function()
  {
  if (xmlhttp_session.readyState==4 && xmlhttp_session.status==200)
    {
      //document.getElementById("myDiv").innerHTML=xmlhttp_session.responseText;
      lefttime = <?php echo $cookie_life; ?>;
      show_session_alert = true;
    }
  });
}

var lefttime=<?php echo $cookie_life; ?>; 
var interval; 
var show_session_alert = true;
interval = setInterval('check_session()',10000); 


function check_session() 
{ 
   lefttime = lefttime - 10; 
   if (show_session_alert && (lefttime <= 50)) {
     show_session_alert = false;

     if (confirm("Your session will expire in "+lefttime+" seconds! Do You want to extend Your session?")) { 
       extend_session();  
     }     
   }   
}


</script>
page 1

Open in new window


This is a countdown script that I like Javascript Countdown


The only problem with this is that it looks like it's called from a div element which I think is not possible on the javascript popup.

Is there any way to merge these two to get the result I'm looking for or is there a better way to do it that won't get flagged by popup blockers?

Thanks
0
Comment
Question by:Mulith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 2000 total points
ID: 37815573
You could try a simple hidden div, as in this jsfiddle.
0
 
LVL 1

Author Comment

by:Mulith
ID: 37815622
Hi Proculopsis,

Yeah that looks pretty good. If the page scrolls down quite a long way would i be able to get it to popup in the center of the users screen even if they are way down the page?

Would I then need to create a function to hide the div again when the user clicks "Extend Session" or "Cancel" within the div?
0
 
LVL 1

Author Comment

by:Mulith
ID: 37846732
Still heard nothing on this ... Could anyone else help?
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question