1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Open new tab using dialog

Discussion in 'HTML & JavaScript' started by manpreet, Mar 5, 2017.

  1. manpreet

    manpreet Regular Member

    Nov 3, 2011
    Likes Received:
    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>

    $(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);
  2. AneaKr

    AneaKr Jr. VIP Jr. VIP

    Oct 15, 2014
    Likes Received:
    SEM Specialist
    Home Page:
    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.