Prevent opening new tab while using two nested ifr

2019-05-23 01:57发布

问题:

Hello stackoverflow fellas, I am facing a problem here. I gave a iframe code to other fella to embed it on his website.

Here is the code of iframe:

  <iframe height="100%" width="100%" frameborder="0" scrolling="auto" src="http://www.mywebsite.com/iframecode" type= "text/javascript"></iframe> 

The above iframe contains following html:

<html>
<head>
</head>
<body>
//... some html code
<iframe src="http://www.paymentgatway.com/pay" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>
//... some html code
</body>
</html>     

Here above htmlcontains another iframe which is used to make a payment(third party).

Problem:

So the problem is when he clicks on pay button which is in second iframe, it opens 3D security page to new tab instead of opening it to same page.

I have tried <base target="_self"/> in <head> tag of my iframe html, but no luck.

I have tested using payment iframe directly, when I click pay button it opens in same window .

Please, can you change my luck?

回答1:

I see two important things:

  1. Mixin HTTP with HTTPS is not a good practice (unless you try to cheat someone) and even if you do, normally the secure page or the browser will block you.
  2. If paymentgatway.com has been coded properly, then it will not allow you to load inside an iframe for security reason

So, based on:

I have tested using payment iframe directly, when I click pay button it opens in same window.

I will say you are facing both scenarios here.

Conclusion:
You can't unless you own both domains and can modify the source code of paymentgatway.com page.



回答2:

Did you try:

<base target="_parent" />

?



标签: html iframe