How to include a Refresh in window.open with _Parent?

Asked

Viewed 131 times

0

I have a form of texts and photos that you send to records.php

And in write.php redirects to.php result with:

<script>window.open("resultado.php?id="+<?=$id?>+"","_parent");</script>

pag result.php receives the id and takes the BD photo (new or changed) and text

<?php
ob_start('ob_gzhandler');
?>
<!DOCTYPE HTML><html dir="ltr" lang="pt-BR">
<head>basico,css,viewport</head>
<body>
<?php
$id=(isset($_GET['id'])) ? (int)$_GET['id'] : 0 ;
if($id>0){
    include $_SERVER['DOCUMENT_ROOT'].'/abre/conexao.php';
    $sel=mysqli_fetch_array(mysqli_query($con,"select * FROM XXXX WHERE id=".$id." LIMIT 1"));
    $foto=$sel['foto'];$texto=$sel['texto'];
    mysqli_close($con);

    if($foto<>''){
        echo"<img src='xxxx/foto.jpg'>";
        }
    echo'<br><b>Texto</b><br>',$texto;
}
echo'</body></html>';
ob_end_flush();

Problem: Qdo the user barter photo and record, the result pag shows the old photo.

You need to update pag or clear cache. (but most do not update)

Question: It is possible to include a refresh in this js ?

or clear the pag cache. result.php?

Thank you in advance

  • Do not use window.open. Use location.href = "resultado.php";.

  • Hello Sam, can you take a look at my problem? I used the suggestion of Taffarel and did not solve. And it seems that it is absent. I thank you very much

  • you can set the name and origin by passing a random string... var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes"; window.open("http://www.sua-url.com.br/", "nome_"+randUrl(), strWindowFeatures); you don’t need to define how _parent...

  • Ivan, include in grava.Asp but do not redirect (white screen) I did so: <script>var strWindowFeatures = "menubar=yes,Location=yes,resizable=yes,scrollbars=yes,status=yes"; window.open("https://site/dir1/pasta1/result.php?ir=2&id=2", "name_"+randUrl(), strWindowFeatures); </script>

  • This save.php is inside an iframe?

  • 2

    Caro Geo don’t use date() or time() to force the cache to update, this will simply cause that at each access you have to repeat the download, the consumption of data of the person will be spent without need, if using filemtime() as I suggested in https://answall.com/a/169846/3635 it will use the modification date of the new file itself as parameter and the browser cache will still be able to take advantage. Here I explain in more detail: https://answall.com/a/57048/3635. Remember to place on every page containing this image.

  • 1
  • I used filemtime() conf. example in issue 169846 and it worked. I thank you all for the super class and teaching material. Sorry for the duplicity (before posting search by window.open)

Show 3 more comments

2 answers

1

Yes, it is possible.

Try this code:

let myWindow = window;
myWindow.open("resultado.php","_parent");
myWindow.location.href="#";

But there are other ways to do it.

  • It was looping in the.php record (I had to abort it)

  • myWindow.location.href="#";

  • Not updating. I tested several times. redirects correct but does not update

  • If you can, enter the code for the resulting.php file..

  • Include in the question the result.php (with 1 photo/text, because it repeats up to 10) and also some more information. Thanks for the attention

  • Taffarel, conf.sua solicitation, I put the code of the file result.php. Any suggestions? Thanks.

  • Managed to solve the problem?

  • Not yet. Ivan (above) gave a suggestion to debug (does not redirect)

Show 3 more comments

0

Add a timestamp in the image path that will avoid browser caching:

echo "<img src='xxxx/foto.jpg?". date("ymdHis") ."'>";

The function date("ymdHis") will always add a unique value every second after the ? (year, month, day, hour, minute and second), making the browser always think it is a different image (e.g..: foto.jpg?191009191137).

Browser other questions tagged

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