1
我在做FreeCodeCamp的隨機引用機練習。鳴叫按鈕打開新窗口和新標籤
使用this answer,我嘗試設置我的推文按鈕來打開一個新窗口,而不是用戶可以使用此引號引用的選項卡。
唯一的問題是它打開一個新標籤以及一個新窗口。有什麼辦法可以打開新窗口嗎?
爲HTML鏈接分享Tweet
<a class="twitter-share-button" href="https://twitter.com/intent/tweet" target="_newwin">
Tweet</a>
相關的JavaScript
jQuery('a[target^="_newwin"]').click(function() {
var width = 500;
var height = 300;
window.open(this.href , 'newwindow', 'width=' + width + ', height=' + height + ', top=' + ((window.innerHeight - height)/2) + ', left=' + ((window.innerWidth - width)/2));
});
謝謝!
在猜測新窗口(或標籤)是因爲錨的默認行爲打開,嘗試http://stackoverflow.com/questions/3786898/jquery-anchor-preventdefault – yuriy636
一個簡單的解決方法是在你的錨上添加'onclick =「return false;」'。 –