1

a group images are calling in a div and there we have given an option to rotate images if required.

Actually the image is rotating but it is not showing in the page( without doing 2 or 3 manual page refresh).

I have added

 <meta HTTP-EQUIV="Pragma" content="no-cache"/>
 <meta HTTP-EQUIV="Cache-Control" content="no-cache"/>

at head

also done

if(isset($_GET['re'])=='re')
{
?>

<script language="JavaScript" type="text/javascript">

var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded)
        window.location.replace(window.location+"?reloaded=true");
}
reloadOnceOnly(); //You can call this via the body tag if desired
</script>

<?php
}

But it is not showing the new rotated or changed image without another manual refresh.

Could you please help me on this?

merlin
  • 81
  • 1
  • 1
  • 6
  • You might want want to change `if(isset($_GET['re'])=='re')` into `if(isset($_GET['re']))` for forward compatibility reasons. It's very strange you're comparing a known `bool` with a known `string` with `==`... **edit** Or if you're actually trying to check its value: `if(isset($_GET['re']) && $_GET['re']=='re')` – Rudie May 03 '11 at 15:22

2 Answers2

0

If I understand you correctly, you're trying to use a PHP to code to refresh the webpage? However, the issue here is that once the PHP is output to the client, you can't have control over it already. The best thing to do in this context is to use JavaScript to do the refresh for you. Hope it helps :)


Hi Merlin, you might want to use a simpler logic like this:

<script type="text/javascript">

    var reloaded = false;
    var loc=""+document.location;

    loc = loc.indexOf("?reloaded=");

    if (loc == -1){
      window.location.replace(window.location+"?reloaded=true");      
    }
</script>

Optionally you might want to pack it into a function for your use. Hope it helps (:

Vern
  • 2,393
  • 1
  • 15
  • 18
  • Now I have used a code to refresh the page. But it is not showing the changed image all the time. – merlin May 03 '11 at 07:17
  • and I would like to add a code to refresh div without refreshing the whole page – merlin May 03 '11 at 07:18
  • For your point on refreshing the div without the whole page, the best is to use a JavaScript with either a setInterval() or setTimeout() function. As for your first point on the refresh not showing, have you checked that it has not been cached in your browser? – Vern May 03 '11 at 07:20
  • merlin, I think your looking to use ajax. – Abe Petrillo May 03 '11 at 07:49
  • @merlin apologies for the late reply. Please see my answer after the horizontal page line. Hope it helps (: – Vern May 03 '11 at 12:28
0

Why not

<script>
function rotate(imgId,direction) {
  var img = document.getElementById(imgId);
  img.src=img.src.split("rotation=")[0]+"rotation="+direction+"&rnd="+new Date().getTime();
  return false;
}
</script>
<img id="image1" src="getimage.php?name=image1&rotation=0" /><br />
<a href="#" onclick="return rotate('image1',0)">Reset</a>
<a href="#" onclick="return rotate('image1',1)">90°</a>
<a href="#" onclick="return rotate('image1',2)">180°</a>
<a href="#" onclick="return rotate('image1',3)">270°</a>
mplungjan
  • 169,008
  • 28
  • 173
  • 236