8

I have many custom tweet buttons on my page that I am dynamically generating using this line of PHP executed in a loop:

echo "<li><a href=\"https://twitter.com/share?text=Check%20out%20{$items[$i]['name']}%20at%20completeset.us/item/{$items[$i]['item_id']}&url=&via=cmpltst\"  class=\"twitter\">T</a></li>";

This works perfectly fine, however, this executes in the same tab and navigates me away from the page it was called from. I would like to open the share dialog in a new window, but my Javascript background is limited to form validation and a few Jquery Ajax calls, so I have no idea how to go about doing this. How could I pop up the dialog in a new window?

jaimerump
  • 882
  • 4
  • 17
  • 35

3 Answers3

21

this worked me fine

<a target=_blank href=\"https://twitter.com/share?text=Check%20out%20{$items[$i]['name']}%20at%20completeset.us/item/{$items[$i]['item_id']}&url=&via=cmpltst\"  class=\"twitter\  onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" >T</a>

add onclick as

 onclick="javascript:window.open(this.href, '', 'menubar=no,
             toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
Arjun
  • 2,159
  • 1
  • 17
  • 26
  • You should not use `javascript:` in the `onclick` attribute, as this attribute is meant to JavaScript only. The `javascript:` should be used when inserting JavaScript code in `href` attribute, ie. `href="javascript:window.open[..]"`. – EMiDU Feb 27 '18 at 17:41
1

You just need to add the "target=_blank" to your a href:

echo "<li><a target=_blank href=\"https://twitter.com/share?text=Check%20out%20{$items[$i]['name']}%20at%20completeset.us/item/{$items[$i]['item_id']}&url=&via=cmpltst\"  class=\"twitter\">T</a></li>";
Developer
  • 2,021
  • 12
  • 11
  • That pops it up in a new tab, so at least the user doesn't lose their place. I was hoping for a separate popup window though. – jaimerump Jul 13 '12 at 15:46
1

Just have an on click Javascript function for your anchor tag anbd in that function use window.open() by passing your URL toopen it in new window.hope this works

Santosh Sidnal
  • 128
  • 1
  • 9
  • That's basically exactly what I ended up doing based on this link: http://www.quirksmode.org/js/popup.html – jaimerump Jul 14 '12 at 14:44