简体   繁体   English

iframe重定向首页时弹出

[英]Popup when iframe redirect top page

I am working on a payment website, which needs to integrate a 3rd party website inside an iframe. 我正在一家支付网站上工作,该网站需要在iframe中集成一个第三方网站。 However, at some point, the user can click a button inside the iframe, which redirects the parent window to another URL. 但是,在某些时候,用户可以单击iframe中的按钮,该按钮会将父窗口重定向到另一个URL。 I cannot touch the 3rd party code. 我无法触摸第三方密码。

Is it possible to capture this URL the parent window is being redirected to, stop this redirection, and pop up another window for that URL? 是否可以捕获要重定向到父窗口的URL,停止该重定向,并为该URL弹出另一个窗口?

Thanks for any help. 谢谢你的帮助。

You will be able to detect when the iframe's url changes , but you will not be able to look at what the new url is. 您将能够检测到iframe的网址何时更改 ,但是您将无法查看新网址是什么。 That may be just enough. 那可能就足够了。 If the user clicks something in the iframe, and the iframe changes url, then you can detect that and redirect the parent window. 如果用户单击iframe中的某些内容,并且iframe更改了网址,那么您可以检测到该内容并重定向父窗口。

Plain javascript solution: 普通的javascript解决方案:

<iframe
  src="https://target.com/page"
  onload="alert('iframe has loaded or changed')">
</iframe>

jQuery solution: jQuery解决方案:

<iframe class="target-iframe" src="https://target.com/page"></iframe>

$(document).on('load', '.target-iframe', function () {
  alert('iframe has loaded or changed')
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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