Open new tab using dialog

manpreet

Power Member
Joined
Nov 3, 2011
Messages
631
Reaction score
156
I am trying to open a link in new tab evoked onblur, however as popup blocker triggers a block I am now trying to sync a dialog to confirm so the the new tab isn't blocked when opening. I am trying to use the below code but I can't seem to work it properly.

The code I would want to use is below. When I click the link alone the dialog seems to be working perfectly and opens new tab, how do I implement so on blur the same dialog is triggered and when user clicks to confirm a new tab is opened without popup blocker getting evoked:

<a href="www.google.com" class="confirmation" target="_blank">Link</a>

<script>
$(window).blur(function() {
var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) {
if (!confirm('Are you sure?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
elems.addEventListener('click', confirmIt, false);
}
})
</script>
 
You might have to make the request synchronous, i.e. the user has to click something to open the popup otherwise the blocker will detect it as spam and block it. Try specifying "async: false" in jQuery.
 
Back
Top