How to pop up new window with tweet button

偶尔善良 提交于 2019-12-23 07:57:56

问题


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?


回答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




回答2:


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;"



回答3:


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>";


来源:https://stackoverflow.com/questions/11473345/how-to-pop-up-new-window-with-tweet-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!