0

I'm using the following code to generate a Facebook share button:

<li>
  <a
    href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fsimplesharingbuttons.com%2F&t="
    target="_blank"
    title="Share on Facebook"
    onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(document.URL) + '&t=' + encodeURIComponent(document.URL)); return false;">
    <i class="fa fa-facebook-square fa-2x"></i>
  </a>
</li>

As you can see, I'm using window.open, but the share dialogs opens in a new browser tab instead of a popup window.

How to modify this code to open the dialog in a popup window?

Codepen: http://codepen.io/alexcheninfo/pen/OXpRjd

alex
  • 7,111
  • 15
  • 50
  • 77

3 Answers3

1

You have to provide extra specification to your window.open() ;

window.open('yourlink','windownam' , 'width=400,height=200,scrollbars=yes');
Akira Lynn
  • 394
  • 3
  • 14
0

Basically, this is controlled by the browser and the browsers options, no good way to force this behavior (window vs tab).

See similar answer here JavaScript open in a new window, not tab which indicates there is a method (height/width) that works (as a hack) on some browsers.

Community
  • 1
  • 1
John Ackerman
  • 1,041
  • 1
  • 9
  • 16
  • Your link indicates a perfectly good way to force the behavior - set a height/width in the `window.open` call. – ceejayoz Jun 28 '16 at 02:34
  • It then indicates that modern browsers (the comments start with FF 11) don't work that way anymore.... – John Ackerman Jun 28 '16 at 02:36
  • That's simply not true, or you wouldn't see popup windows used at all anymore. Facebook uses them extensively in their JS SDK. Here, try this: http://codepen.io/ceejayoz/pen/OXpRvG – ceejayoz Jun 28 '16 at 02:42
  • Try this with your codepen, open it up in IE edge, then open up IE options and click the "Tabs" button within the General tab. Tell IE to "Always open pop-ups in a new tab" and suddenly, your pen for open a new window will open a new tab. Like I said, you don't have ultimate control over this. – John Ackerman Jun 28 '16 at 17:19
  • Yes, if you've gone and enabled an *optional, non-default* feature that explicitly stops popups of any sort, this won't work. That's fairly obvious, and fairly irrelevant to OP's question. OP left off height/width in their `window.open` call. Adding it's going to make it a popup for essentially all visitors, as they'd hoped for. – ceejayoz Jun 28 '16 at 17:22
0

Please try with this:

window.open("http://www.w3schools.com", '_blank', 'left=20,top=20,width=950,height=650');

The second parameter is '_blank' The third parameter is some specifications that are separated by comma: height, width,....

tavsta
  • 11
  • 3