window.open默认阻止(弹出窗口被阻止) [英] window.open blocked by default (popups blocked)

查看:587
本文介绍了window.open默认阻止(弹出窗口被阻止)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的网站分享连结,并有以下程式码:

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)

html (JADE)

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

但是,当弹出窗口被阻止时,这不起作用。

How can I get around popup blocked issue???

推荐答案

不知道如何修复, >你想添加许多共享链接吗?并且因为如果您不在链接 href 中包含 window.open ,浏览器将阻止弹出窗口。

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

所以你必须在 href 中创建 window.open 像这样。

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

示例: 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>');

});

这篇关于window.open默认阻止(弹出窗口被阻止)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆