我的页面上有一个弹出推文框来分享网站。我正在使用这段代码:
<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>
在 html 中加上这个:
<a href="#" onclick="fbs_click();" ><img class="right" src="twitter.png">
这一切都很好,但是当我点击 tweet 时,窗口将保持打开状态,然后转到 twitter 主页。单击推文后是否有关闭此窗口的方法?
最佳答案
如果你将它保存到一个变量中,比如:
var win = window.open( ...
你可以用
关闭它win.close();
https://developer.mozilla.org/en-US/docs/Web/API/Window/close
至于放在哪里,查看推特的Web Intent事件:
twttr.events.bind(
'tweet',
function (event) {
// Do something there
}
);
关于javascript - 点击推文后弹出推文框并关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30028338/