简体   繁体   English

弹出推文框并在单击推文后将其关闭

[英]Popup tweet box and closing it after clicking tweet

I have a popup tweet box on my page to share the site. 我的页面上有一个弹出式推文框,用于共享该网站。 I am using this code: 我正在使用此代码:

<script type="text/javascript">
function fbs_click() {
    var twtTitle = document.title;
    var twtUrl = location.href;
    var maxLength = 140 - (twtUrl.length + 1);
    if (twtTitle.length > maxLength) {
        twtTitle = twtTitle.substr(0, (maxLength - 3)) + '...';
    }
    var twtLink = 'https://twitter.com/home?status=go%20to%20this%20site!';
    var x = screen.width/2 - 520/2; 
    var y = screen.height/2 - 350/2-100; 
    window.open(twtLink, '','height=350,width=520,left='+x+',top='+y);
}
</script>

With this in the html: 与此在HTML:

<a href="#" onclick="fbs_click();" ><img class="right" src="twitter.png">

This all works well however when I click tweet the window will remain open and then go to the twitter homepage. 这一切都很好,但是当我单击tweet时,该窗口将保持打开状态,然后转到Twitter主页。 Is there anyway to get this window to close after clicking tweet? 无论如何,单击推文后是否可以关闭此窗口?

If you save it to a variable like: 如果将其保存到类似这样的变量中:

var win = window.open( ...

You can close it with 您可以用关闭它

win.close();

https://developer.mozilla.org/en-US/docs/Web/API/Window/close https://developer.mozilla.org/zh-CN/docs/Web/API/Window/close

As for where to put this, check out Twitter's Web Intent events: 至于放在哪里,请查看Twitter的Web Intent事件:

twttr.events.bind(
    'tweet',
    function (event) {
        // Do something there
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM