-1

I use this script:

<div id="accesso" class="spalla_basic grigio_type clearfix">
    <iframe src="test.php" frameborder="0" width="257" height="160" marginheight="0" marginwidth="0" scrolling="no"></iframe>
</div>

In my homepage I have the above code. And when I press yes on the above block it will redirect to a new page.
But my problem is: when I click on this block, it redirect me to a new page but with in this block.

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
elise
  • 15
  • 8
  • 1
    So when you press "Yes" it is running code in some other domain, not yours. So you have no control over what the "Yes" button does – RiggsFolly Feb 23 '17 at 09:01
  • no no.. from this little box when i pres yes is redirect from a new page.. but the redirect is only on this little box not in entire page. – elise Feb 23 '17 at 09:04
  • Everything will happen in the iframe unless the other sites code forces a new tab – RiggsFolly Feb 23 '17 at 09:06
  • Have you tried what they suggest here?http://stackoverflow.com/questions/15712880/load-iframe-links-into-parent-window – Asons Feb 23 '17 at 09:07
  • Try this solution : [How to make all links in an iframe open in new tab](http://stackoverflow.com/questions/22808065/how-to-make-all-links-in-an-iframe-open-in-new-tab) – Ranap Manalu Feb 23 '17 at 09:10
  • ok.. ty for so many links.. but i dont know php/html/java so good.. im newbie.. can you make a example for me please? – elise Feb 23 '17 at 09:16
  • Note, you **can't control** whether it opens in a tab or new window, this is solely up to the user and how (s)he set up their browser – Asons Feb 23 '17 at 09:16
  • thanks i solved. with 4 files :D ty for your time. respect – elise Feb 23 '17 at 10:15
  • corrected grammar, and also make it more easily readable. – Raunak Gupta Feb 23 '17 at 14:00

1 Answers1

0

So you basically want the page within iframe to escape the frame and load in a different tab after you click over the button ? Is that what you are trying to accomplish ?

Try adding the following code to the <head> section.

<script type="text/javascript">
    if (top.location!= self.location){
        top.location = self.location
    }
</script>

The following is the HTML file with your iframe which loads your PHP code that has a button.

<html>
<body>
<iframe src="sample.php">
</body>
</html>

Suppose landing.php is the page that you get redirected to after clicking over the button. The JavaScript code should be incorporated in landing.php

<?php
echo "<html>
<head>
<script type="text/javascript">
    if (top.location!= self.location){
        top.location = self.location
    }
</script>
</head>";

?>
Arun
  • 136
  • 1
  • 10
  • i add this after i see and nothing change.. i do something wrong? PS: im new with php/html/java etc.. – elise Feb 23 '17 at 09:17
  • one problem..in – elise Feb 23 '17 at 09:45
  • Do you really have control on the landing page ? I mean the page that you get redirected to after pressing the button. We are considering 3 files here. First one is your HTML page. 2nd one is the php page that has a button in it. 3rd one is the landing page( the page you get redirected to after clicking the button). The JavaScript code should go on top of the landing page. – Arun Feb 23 '17 at 09:49
  • thanks i solved. with 4 files :D ty for your time. respect – elise Feb 23 '17 at 10:14