views:

249

answers:

4
<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)

+2  A: 

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

Pekka
+1  A: 

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.

quixoto
+3  A: 

To open in a new windows with dimensions and everything, you will need to call a javascriupt 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

Marcos Placona
you can write insted of `javascript:void(0);` shorter `javascript:;`
c0mrade
or "#" even :-)
Marcos Placona
@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
c0mrade
How do I make that popup window not show my address bar, google toolbar, etc?
TIMEX
@alex simply change toolbar from 1 to 0
Marcos Placona
@c0mrade true, but the # sometimes help when you have ajax on the page. Varies from case to case :-)
Marcos Placona
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
@bobince so you say its bad idea, where can I find more info about that, by the way I didn't downvote..
c0mrade
thanks for that @bobince. Besides your harsh -1, I guess I learned something off you, and made my example better.
Marcos Placona
Some discussion of JavaScript link actions in general in this question and answer. http://stackoverflow.com/questions/1291942/what-does-javascriptvoid0-mean/1293130#1293130
bobince
@mplacona: the harsh -1 is gone now the answer is improved :-)
bobince
I think you should also look into using the rel attribute and then having some unobtrusive javascript that fires on the click of an anchor that has a rel attribute of "external" or something similar, which like bob says gets the href value and then opens the new window. Thanks
Pricey
Do not return `false` without checking if the new window really exists. Some pop up blockers just open and close such windows very fast in the background. The user just sees a dead link in this case.And fixed windows sizes are rude to readers with big font sizes. They may prefer a full screen window. Respect this.
toscho