简体   繁体   中英

How to prevent opening new tab or window while browsing in iframe

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?

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');
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM