GJain
GJain

Reputation: 5093

window.open blocked by default (popups blocked)

I am trying to have share link for my site and had following code:

function handleFacebook(shortURL) {
  $(".facebook").click(function(e) {
    e.preventDefault();
      window.open(
        'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(shortURL),
        'facebook-share-dialog',
        'width=626,height=436');
      return false;
    });
  });
}

html (JADE)

  div.facebook
    img(src="/images/facebook_logo.png")

However, this does not work when popups are blocked.

How can I get around popup blocked issue???

Not sure how to fix and where/what to add??

Upvotes: 0

Views: 774

Answers (1)

Chokchai
Chokchai

Reputation: 1722

You want to added many share links right ? and because the browser will blocked popup if you not include window.open in link href.

So you have to create entire of link with window.open in its href like this one.

Example: FIDDLE

var url = ['http://google.com', 'http://bing.com', 'http://duckduckgo.com/'];

$.each(url, function(i, val){

    $('body').append('<div><a href="#" onclick="window.open(\'https://www.facebook.com/sharer/sharer.php?u=\'+encodeURIComponent(\''+val+'\'), \'facebook-share-dialog\', \'width=626,height=436\'); return false;"> Share on Facebook </a></div>');

});

Upvotes: 2

Related Questions