JQuery blockUI auto redirect

I use blockUI and its work is very good.

The only thing I can't seem to do is redirect to another URL after x seconds. I can make it redirect, but it does not take into account setTimeout ...

Could anyone do this?

<script type="text/javascript">
    $(document).ready(function() { 
        $('#demo2').click(function() { 
            $.blockUI({ css: { 
                border: 'none', 
                padding: '15px',
                color: '#fff',
                backgroundColor: '#54bdd9', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: 1.5, 
                color: '#fff' 
            } }); 

            setTimeout($.unblockUI, 6000),$(window.location).attr('href', 'http://www.mydomain.co.uk');

        }); 
    }); 
</script>

If anyone can shed light, that would be great.

Thank.

+3
source share
1 answer

It has been a while, but I was just looking for it. After the experiments, it seems that BlockUI does not prevent window navigation, so you don’t even need to unlock it. Just delay and move.

$('#demo2').click(function () {
  $.blockUI({
    css: {
      border: 'none',
      padding: '15px',
      color: '#fff',
      backgroundColor: '#54bdd9',
      '-webkit-border-radius': '10px',
      '-moz-border-radius': '10px',
      opacity: 1.5,
      color: '#fff'
    }
  });

  setTimeout(function() { window.location.href = "http://www.google.com/"; }, 6000);
});

(There are various discussions on how to set the location of the window. I'm not going to discuss it here. This window.location.hrefis exactly how I do it.)

0
source

All Articles