0

I have this very simple script of jQuery plugin called blockUI
I found many posts with the same issue but no resolution
Can someone take a look at this snippet or suggest an alternative to blockUI?
Thank you!

function block() {
alert('gonna block')
  $.blockUI();
  setTimeout(unBlock(), 5000); 
}

function unBlock() {
	$.unblockUI();
}

function alertUser() {  
  alert('Alert User'); 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"></script>

<button onclick="alertUser()">Alert</button>
<button onclick="block()">Block!</button>
<button onclick="unBlock()">UnBlock!</button>

2 Answers 2

2

It does work but you are calling unblock instantly and it goes away, pass the function into setTimeout instead of calling it.

function block() {
  $.blockUI();
  setTimeout(unBlock, 5000); 
}

function unBlock() {
  $.unblockUI();
}

function alertUser() {  
  alert('Alert User'); 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"></script>

<button onclick="alertUser()">Alert</button>
<button onclick="block()">Block!</button>
<button onclick="unBlock()">UnBlock!</button>

Sign up to request clarification or add additional context in comments.

Comments

2

You need to include jQuery before you include any plugins.

Change the order of your includes.

1 Comment

addin the 2 scripts mentioned above worked for me in a Wordpress installation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.