Iframe src caching issue on firefox

Viewed 6765

I have an iframe element with a random scr attribute. When I do refresh the page every time, the iframe should load the page with different query parameters based on the src attribute. But in firefox, if I try to load dynamic URL in an iframe, it always execute the first time executed URL eventhough the src attribute changes dynamically. The query parameters also not passing correctly. So, how I can solve this issue?

eg:

<?php

$url = "http://localhost/test.php";

$rand_val = rand(1000, 9999);

echo "<iframe name='dynamicload' src='{$url}?rand_val={$rand_val}'></iframe>";

?>
4 Answers

It's reported as a bug of firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=279048

one workaround is resetting the src of iframe: document.getElementById('iframe_id').src = 'target_url';

Still there will be two requests: the first request is wrong and cancelled immediately before the second request which is correct.

All other answers doesn't work in my case. So I decided to solve the problem my creating the total iFrame dynamically with JavaScript like it is described in this answer:

<div id="dynamicload"></div>

<script type="text/javascript">
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "http://localhost/test.php?rand_val=<?php echo $rand_val; ?>");
    ifrm.style.width = "500px";
    ifrm.style.height = "500px";
    document.getElementById("dynamicload").appendChild(ifrm);
</script>
Related