如何防止在iframe中浏览时打开新选项卡或窗口 [英] How to prevent opening new tab or window while browsing in iframe

查看:4446
本文介绍了如何防止在iframe中浏览时打开新选项卡或窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

While browsing through iframe window I want to prevent any popups. Also when i click on link that wants to open new tab or window I want to get the url and put it into iframe.src. I found that there is a window.open method that opens the new tabs or windows but how to stop it and take the url?

推荐答案

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

You can override window.open with your own function:

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的任何内容之前定义此函数

Just make sure this function is defined before anything that uses window.open

这篇关于如何防止在iframe中浏览时打开新选项卡或窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆