Load Iframe Target into a new Main Window Tab

Asked

Viewed 1,585 times

0

I have an HTML page that incorporates a code iframe, my problem is that this embedded code has a form, which when filled out needs to be opened in a new tab, but this tab is opened inside the div where the iframe is embedded, I need this new tab to open in the main window.

Important

The iframe page (embedded page) is in the same domain as the main page and I have access to it, so I can put any jquery code / javascript in it.

Iframe code:

<iframe src="http://siteexemplo.com.br/index2.php" scrolling="no" style=" width: 100%; height: 100px; overflow: hidden;"></iframe>

This iframe page contains a form with the following HTML.

HTML of the embedded page

<form class="form-signin" action="validacao.php" method="post" target="_self">
    <div style="width:60%; float:left">
        <input type="password" name="senha" id="inputPassword" style="height:47px" class="form-control" placeholder="Senha" required>
    </div>
    <div style="width:39%; float:right">
        <button class="btn btn-lg btn-primary btn-block" type="submit" ><a style="color:#ffffff; text-decoration:none" >Visualizar</a></button>
    </div>

</form>

Can someone help me?

2 answers

0


One way to solve this is to pass inside the iframe the URL of what you want to open in the other window, the script takes the content of the page and sends it to the browser, then you will have the content you want on the page, but the address of another site, an example in php can be:

http://yourdomain.com/getURL.php?url=http:www.google.com

reference and further explanations in the original English text: https://stackoverflow.com/questions/4583792/make-links-inside-an-iframe-open-in-a-new-window

0

Man, just to be sure: have you ever tried changing the target of the form inside the iframe to "_Blank"? It would look like this:

<form class="form-signin" action="validacao.php" method="post" target="_blank">
  ...
</form>

Not working, you can capture the form submission with the event .onsubmit or $().submit and go up to frame parent. For this, picks up the object window.parent that you will use to open the new tab. It would look something like

window.parent.open("endereço do GET", "_blank")

Of course, since your form is POST, you may need to let the form run what it needs and pass a temporary GET address. In this case, as it seems to be authentication, the server response would arrive by the iframe itself with the Session cookie, hence it would be okay to include the JS code to execute only in the POST response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.