【问题标题】:How to prevent opening new tab or window while browsing in iframe如何防止在 iframe 中浏览时打开新标签页或窗口
【发布时间】:2011-09-14 15:33:58
【问题描述】:

在浏览 iframe 窗口时,我想阻止任何弹出窗口。此外,当我单击想要打开新选项卡或窗口的链接时,我想获取 url 并将其放入 iframe.src。我发现有一个 window.open 方法可以打开新的选项卡或窗口,但是如何停止它并获取 url?

【问题讨论】:

  • 我们是来自同一个域还是其他人的 iframe 的内容?

标签: javascript jquery html iframe


【解决方案1】:

您可以使用自己的函数覆盖 window.open:

var oldWindowOpen = window.open;
window.open = function (url, name, features, replace) {
  // handle window.open yourself
  myIframe.src = url;
  // if you want to use functionality of original window.open call the oldWindowOpen function
  oldWindowOpen(url, 'myName', 'myFeatures');
}

只要确保这个函数在任何使用 window.open 的东西之前被定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    相关资源
    最近更新 更多