【问题标题】:inline javascript popup function not working in IE11 and below内联 javascript 弹出功能在 IE11 及以下版本中不起作用
【发布时间】:2017-03-28 08:20:40
【问题描述】:

我有一个像这样的内联 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('...')",但它不起作用。

非常感谢任何帮助。 :)

【问题讨论】:

  • 您看不到您要打开的网址吗?使用 onclick。
  • 它有效!谢谢。我对 js 很不好 :)
  • 实际上这适用于 IE 但不适用于 iOS...

标签: javascript html function internet-explorer-11 target


【解决方案1】:

你的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")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 2019-09-19
    • 1970-01-01
    相关资源
    最近更新 更多