我有一个带有随机scr属性的iframe元素.当我每次都刷新页面时,iframe应该根据src属性加载具有不同查询参数的页面.但是在firefox中,如果我尝试在iframe中加载动态URL,它总是执行第一次执行的URL,尽管src属性动态变化.查询参数也未正确传递.那么,我怎么能解决这个问题呢?
例如:
<?php
$url = "http://localhost/test.php";
$rand_val = rand(1000, 9999);
echo "<iframe name='dynamicload' src='{$url}?rand_val={$rand_val}'></iframe>";
?>
Run Code Online (Sandbox Code Playgroud)
我们在Firefox中将iframe src缓存并禁用原始页面以及iframe页面没有帮助时遇到了同样的问题。我们将以下代码(jQuery代码)放入iframe的onload函数中:
$(parent.document).find("iframe").each(function() {
// apply the logic only to the current iframe only
if(this.contentDocument == window.document) {
// if the href of the iframe is not same as
// the value of src attribute then reload it
if(this.src != location.href) {
this.src = this.src;
}
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6042 次 |
最近记录: |