45
<a href="facebook.com/sharer" target="_blank" >Share this</a>

How do I make this a certain width and height, in a new window, when the user clicks on it? In firefox, the current code only opens up a new tab (not a new window)

CC BY-SA 2.5
1
  • 1
    In Firefox it opens in a new tab instead because the majority of users hate popup windows. Please bear this in mind before opening a popup.
    – bobince
    Mar 29, 2010 at 22:17

3 Answers 3

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

132

To open in a new windows with dimensions and everything, you will need to call a JavaScript function, as target="_blank" won't let you adjust sizes. An example would be:

<a href="http://www.facebook.com/sharer" onclick="window.open(this.href, 'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" >Share this</a>

Hope this helps you.

CC BY-SA 3.0
12
  • 3
    you can write insted of javascript:void(0); shorter javascript:;
    – ant
    Mar 29, 2010 at 21:32
  • @mplacona I prefer javascript:; , because if you have # and hit return on the keyboard the page will not get refreshed but with this works like a charm
    – ant
    Mar 29, 2010 at 21:39
  • 20
    This is just horrible for accessibility, usability, and SEO. Never, ever, javascript:. To stop a # link scrolling to the top, just return false in the click event handler. But a link without a proper href is a good sign you are doing something wrong. Either have a button for an action that goes nowhere, or, in cases like this where there is a real URL to link to, put it in the href and read it from the handler. <a href="http://www.facebook.com/sharer" onclick="open(this.href, '_blank', '...'); return false;">...</a>.
    – bobince
    Mar 29, 2010 at 22:14
  • 5
    thanks for that @bobince. Besides your harsh -1, I guess I learned something off you, and made my example better. Mar 29, 2010 at 22:32
  • 4
    @mplacona: the harsh -1 is gone now the answer is improved :-)
    – bobince
    Mar 29, 2010 at 22:44
3

You can't influence neither type (tab/window) nor dimensions that way. You'll have to use JavaScript's window.open() for that.

CC BY-SA 2.5
2

You don't have that kind of control with a bare a tag. But you can hook up the tag's onclick handler to call window.open(...) with the right parameters. See here for examples: https://developer.mozilla.org/En/DOM/Window.open

I still don't think you can force window over tab directly though-- that depends on the browser and the user's settings.

CC BY-SA 2.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.