jQuery trigger custom event synchronously

To force anything to be synchronous using jQuery:


$.when($(this).trigger('custom-event')).done(function(){
window.location.href = 'url';
});

trigger event is sychronous it makes an effect running inside the triggered event, and the expected method was being called inside the callback.

Stackoverflow: jQuery trigger custom event synchronously

jQuery.when function