2013-11-02 32 views
0

我想创建一个分享按钮从博客作者到我的帖子下的tumblr。使用高级选项我几乎实现了我的目标,但代码不是打开新窗口,而是使用与共享帖子相同的选项卡,并在最后一秒关闭选项卡时挂起。Tumblr在Blogger上的自定义分享按钮 - 打开弹出窗口

如何更改代码以打开良好的弹出窗口?

<!-- Put this tag wherever you want your button to appear --> 
<span id="tumblr_button_abc123"></span> 

<!-- Set these variables wherever convenient --> 
<script type="text/javascript"> 
    var tumblr_link_url = "http://www.example.com/permalink/my-article"; 
    var tumblr_link_name = "My Awesome Article"; 
    var tumblr_link_description = "Lorem ipsum..."; 
</script> 

<!-- Put this code at the bottom of your page --> 
<script type="text/javascript"> 
    var tumblr_button = document.createElement("a"); 
    tumblr_button.setAttribute("href", "http://www.tumblr.com/share/link?url=" + encodeURIComponent(tumblr_link_url) + "&name=" + encodeURIComponent(tumblr_link_name) + "&description=" + encodeURIComponent(tumblr_link_description)); 
    tumblr_button.setAttribute("title", "Share on Tumblr"); 
    tumblr_button.setAttribute("style", "display:inline-block; text-indent:-9999px; overflow:hidden; width:20px; height:20px; background:url('http://platform.tumblr.com/v1/share_4.png') top left no-repeat transparent;"); 
    tumblr_button.innerHTML = "Share on Tumblr"; 
    document.getElementById("tumblr_button_abc123").appendChild(tumblr_button); 
</script> 

回答

1

你可以改变的链接目标:

tumblr_button.setAttribute("target", "_blank"); 

但是,如果你想控制的尺寸(并保证其在新标签页,而不是不渲染),你想要做的事更像是:

tumblr_button.setAttribute("onclick", "window.open(this.href, 'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"); 

后者溶液从here借来的,但你可能也想看看this IE兼容性问题。

+0

谢谢,它工作得很好。 – Archarachne

相关问题