0

Is there any way to flash jquery dialog box on the browser to let user know something important needs to be done if he is on other window. Lets take the case for timeout popup where user needs to extend his session, so if we could flash the dialog then user is notified when he is on other page.

Actually its a timeout jquery popup for which I want user's attention, so that he can take appropriate action.

alice7
  • 3,834
  • 14
  • 64
  • 93
  • 2
    Sure there is. What have you tried? – j08691 Jun 27 '12 at 16:28
  • You want to let a dialog in an invisible tab/window of the browser be visible ? Is that your question ? – Denys Séguret Jun 27 '12 at 16:28
  • to be honest, I couldn't find any jquery dialog exmaple which shows this. – alice7 Jun 27 '12 at 16:29
  • Do you want to do it with our without page reload? – mvbl fst Jun 27 '12 at 16:30
  • @dystroy: I want to flash my jquery dialog to get user's attention which is currently not happening. – alice7 Jun 27 '12 at 16:30
  • maybe a facebook like notification on the page title when someone write on tchat ,do you see what i mean? – khaled_webdev Jun 27 '12 at 16:32
  • other page is other page of other sites (other tab) ? – khaled_webdev Jun 27 '12 at 16:33
  • other page is other tab like facebook or google etc. – alice7 Jun 27 '12 at 16:37
  • You need to use cookie to know when the session has been started. Understand that the session expiration should persist with page reloads. Use a cookie lib (set, get, destroy) to set initial session expiration. On each page load, read that cookie and calculate time remaining in the session. Then set a timeout with this remaining time in milliseconds with a callback that shows the dialog. – mvbl fst Jun 27 '12 at 16:37

2 Answers2

0

It's not exactly what you're talking about, but I think the UI effect you actually need is a dynamic favicon change, as described in: Is it possible change favicon on site when users change themes?

Using that, you can swap the favicon back and forth with some kind of alert icon every second or so until the user returns to the window.

Community
  • 1
  • 1
chaos
  • 122,029
  • 33
  • 303
  • 309
0

This is expanded version of my comment.

Say you have this JS cookie object:

var Cookie = {
  set: function(name,value,seconds) {
    var date = new Date;
    date.setTime(date.getTime() + (typeof seconds != "undefined" ? seconds : 1) * 1000);
    document.cookie = name + "=" + value + "; expires=" + date.toGMTString() + "; path=/; domain=." + vitalPage.getDomain();
  },
  get: function(name){
    var re = new RegExp("(?:^| )" + name + "=([^;]*)", "i");
    var matches = document.cookie.match(re);
    return matches && matches.length == 2 ? matches[1] : null;
  },
  read: function(name){
    var re = new RegExp("(?:^| )" + name + "=([^;]*)", "i");
    var matches = document.cookie.match(re);
    return matches && matches.length == 2 ? matches[1] : null;
  },
  unset: function(name){
    this.set(name,'',-1);
  }
}

On initial page load, do this:

var sess_expires = Cookie.get('sess_expires'),
    sess_remaining,
    show_dialog = function() {
      $('#your_dialog_id').show();
    }

if (sess_expires !== null) {
  sess_remaining = sess_expires - new Date();
  if (sess_remaining > 0) {
    window.setTimeout(show_dialog, sess_remaining); // show dialog when session expires
  }
  else show_dialog(); // show dialog now - session expired
}
else {
  Cookie.set('sess_expires', new Date() + 1800000);
  window.setTimeout(show_dialog, 1800000); // show dialog when session expires
}
mvbl fst
  • 5,213
  • 8
  • 42
  • 59