Javascript 如何使用推文按钮弹出新窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11473345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pop up new window with tweet button
提问by jaimerump
I have many custom tweet buttons on my page that I am dynamically generating using this line of PHP executed in a loop:
我的页面上有许多自定义推文按钮,我使用在循环中执行的这行 PHP 动态生成这些按钮:
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?
这工作得很好,但是,它在同一个选项卡中执行并将我导航到它被调用的页面之外。我想在新窗口中打开共享对话框,但我的 Javascript 背景仅限于表单验证和一些 Jquery Ajax 调用,所以我不知道如何去做。如何在新窗口中弹出对话框?
采纳答案by Santosh Sidnal
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
只需在该函数中使用 window.open() 通过传递您的 URL 在新窗口中打开它来为您的锚标记 anbd 设置一个单击 Javascript 函数。希望这有效
回答by Arjun
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 为
onclick="javascript:window.open(this.href, '', 'menubar=no,
toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
回答by Developer
You just need to add the "target=_blank" to your a href:
您只需要将“target=_blank”添加到您的 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>";