我有这样的内联html链接:
<a href="javascript:myPopup('https://twitter.com/share?url=http://website.com')" target="_blank">my link</a>
这是它应该执行的功能:
//分享弹出窗口
function myPopup(url) {
var leftPosition, topPosition;
leftPosition = (window.screen.width / 2) - ((566 / 2) + 10);
topPosition = (window.screen.height / 2) - ((576 / 2) + 50);
window.open(url, "myWindow", "status = 1, height = 576, width = 566, resizable = 0,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no")
}
除IE11及以下版本外,它在任何地方都可以正常使用。 在IE11及其下方,链接将在新标签页中打开
我最初认为这是因为弹出阻塞或其他东西,但我不认为是这种情况。我已将href=""
更改为href="myPopup('...')"
,但它无效。
非常感谢任何帮助。 :)
答案 0 :(得分:0)
您的HTML代码错误,请使用以下代码
<a href="#" onClick="javascript::myPopup('https://twitter.com/share?url=http://website.com');" target="_blank">my link</a>
function myPopup(url) {
var leftPosition, topPosition;
leftPosition = (window.screen.width / 2) - ((566 / 2) + 10);
topPosition = (window.screen.height / 2) - ((576 / 2) + 50);
window.open(url, "myWindow", "status = 1, height = 576, width = 566, resizable = 0,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no")
}