Jump to content

refresh parent from iframe.


cjkeane

Recommended Posts

hi everyone.

 

i have content in an iframe. when a delete link in a form, is clicked. i need the parent window to be refreshed.

 

i currently have the code below. it seems to refresh the page but not the content. for example, if i manually refresh the page, the data will display, but an automatic refresh through javascript doesn't refresh the content in the iframe. i'd appreaciate the assistance. thanks.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
    
<link href="styles.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function refresh_parent(){
    parent.location.reload();
}
</script>

</head>

<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr> 
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
<input name="userfile" type="file" id="userfile"> 
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload " onclick="refresh_parent()"></td>
</tr>
</table>
</form>

          <table>
            <tr>
                <th align="left" width="300px">Filename: </th>
                <th align="left" width="200px">Type: </th>
                <th align="left" width="60px">Size: </th>
            </tr>
<?php
if (mysql_num_rows($filelist) > 0) {
  		while ($f = mysql_fetch_array($filelist)) {

		 //GET FILE SIZE 
        $fileSize = $f['size'];

        if ($fileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB 
            $theDiv = $fileSize / 1000000; 
            $fileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces) 
        } else { //OTHERWISE DISPLAY AS KB 
            $theDiv = $fileSize / 1000; 
            $fileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces) 
        } 
?>

            <tr valign="top">
                <td width="300px"><?php echo $f['name']; ?> </td> 
                <td width="200px"><?php echo $f['type']; ?> </td> 
                <td width="60px"><?php echo $fileSize; ?> </td> 
                <td>
                    [<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=view&id=<?php echo $f['id']; ?>">DNLD</a> |
                    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=delete&id=<?php echo $f['id']; ?>" onclick="refresh_parent()">Delete</a>]
                </td>
            </tr>
<?php
}
} else {
?>
		<tr><td colspan="3">No Files!</td></tr>
<?php
}
?>
	</table>

</body>
</html>
</script>


 

Link to comment
https://forums.phpfreaks.com/topic/233140-refresh-parent-from-iframe/
Share on other sites

It may be that the browser is caching the page, and refreshing the parent doesn't refresh the frame's cache. What you could do to guarantee the cache-bust, is add a random number on to the src of the iframe, for example:

 

<iframe src="iframe-page.php?rid=<?php echo rand(); ?>"></iframe>

 

To the browser that will be a different page, and cache separately.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.