3

Is it possible to open a popup window without user action, at least a blank popup without being blocked by popup blocker?

My goal is to open a popup window to confirm if user is at PC after a certain amount of time. For example the user has visited my site and left it open in the browser. After say 1 hr I want to show popup which will simply ask if user is there or not and if the user is not at their, PC I want to redirect the user to a different page of my site.

Any clues on how I can do this?

Already gone through this stackoverflow post which was not helpful

Apologies missed important part of issue, I am good with the time part but I need to bypass the popup blocker

Can we manually override pop-up blocker?

Community
  • 1
  • 1
  • You can set variable and increment value every n seconds and turn value to zero by event mousemove. And when variable value will be greater or more than hour show popup. – wmbtrmb Feb 27 '14 at 07:09

8 Answers8

0

Try to use a timer

setTimeout('window.open(url")', miliseconds);
Ziem
  • 6,579
  • 8
  • 53
  • 86
Rafa Hernández
  • 468
  • 7
  • 19
0

Pop up blockers will block the pop up windows triggered without user actions. The solution in your case to go for some js modal pop ups.

You can use https://jqueryui.com/dialog/

Or a simple confirm box will also serve your purpose:

var response = confirm("are you there")?

But you can't customize the confirm box according to your site theme.

Ramesh
  • 4,223
  • 2
  • 16
  • 24
  • using confirm will not work with the OP's use case, since if the user is not at the PC, they will never answer the confirm, and no javascript will ever execute until the user returns and responds. This includes setTimeouts, since confirm is synchronous, and javascript is single threaded. – Thayne Feb 27 '14 at 07:22
0

use setTimeout function read

setTimeout(functionName, delaytime) - Function will excuter after a specified delay

Pramod
  • 141
  • 3
0

you can use this but it is not correct solution but it is working

  var timeoutTime = 1800000;
        var timeoutTimer =   setTimeout(function(){
            alert("TimeOut");
          }, timeoutTime);
        $(document).ready(function() {
            $('body').bind('mousedown keydown', function(event) {
                clearTimeout(timeoutTimer);
                timeoutTimer = setTimeout(function(){
            alert("TimeOut");
          }, timeoutTime);
            });
        });
user2075328
  • 423
  • 2
  • 7
  • 16
0

If you want a full window popup, you cannot do this unless the user has disabled the popup blocker for your site. However, if a modal dialog will work for you, and you are content with just knowing if the user is still viewing your page, you can use something like the following:

setTimeout(function() {
    var timeout = setTimeout(function() {
        //logic to redirect if the user hasn't responded to dialog yet.
    }, 60000); //waits 1 minute for response, change as needed
    $('#dialog-element').on('dialogclose', function() {
        clearTimeout(timeout);
        $('#dialog-element').off('dialogclose');
    });
}, 3600000); //one hour wait

This assumes you are using jQuery UI, and have set up $('#dialog-element') as a modal dialog (see http://jqueryui.com/dialog/).

Thayne
  • 6,619
  • 2
  • 42
  • 67
0

You can create a time counter and use jQuery to detect mousemove and keypress event. After a certain amount of time, a dialog pops up and you can add more redirection logics to it as you see fit:

Demo Fiddle

For testing purposes, set the increment to 1000(1 second) instead of 60000 and the time checker to over 2 seconds:

var idleInterval = setInterval(timerIncrement, 1000); // 1 second
....
function timerIncrement() {
    idleTime = idleTime + 1;
    if (idleTime > 2) { // 2 seconds

Reference:

Detect idle time in JS

jQuery UI Dialog

Community
  • 1
  • 1
Quinn
  • 458
  • 2
  • 8
0

Well, you can try this code !

var timeoutTime = 1800000;
        var timeoutTimer =   setTimeout(function(){
            alert("TimeOut");
          }, timeoutTime);
        $(document).ready(function() {
            $('body').bind('mousedown keydown', function(event) {
                clearTimeout(timeoutTimer);
                timeoutTimer = setTimeout(function(){
            alert("TimeOut");
          }, timeoutTime);
            });
        });
piyush
  • 1
  • 2
-1

You can do this things by using javascript, and for example bootstrap framework.

// time argument shows after how much time we must show popup
var set = function(time){
  setTimeout(function(){
    // logic of open popup
  });
}

set(10000); //10 seconds

To understand how use bootstrap modals(popup) you must read this

Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37