在使用 laravel 响应时强制 iframe 刷新



我正在制作一个应用程序,它有一个部分,它从目录中读取,抓取下一个文件并允许您操作它。

我的页面有 2 个部分,1 个部分是当前文件的详细信息,另一个部分是文件的预览。每次我的页面刷新时,它都会从指定的目录中获取下一个文档并将其显示为 iframe,以便用户可以预览它,但我在刷新 iframe 时遇到问题。

当页面重新加载时,它会像它应该做的那样显示下一个文件的文本和名称,但预览仍然显示我刚刚处理的文件,直到我强制刷新页面几次并等待。

我已经尝试了很多不同的方法来强制加载iframe,但似乎没有一种能够流畅地显示它。

.PHP

public function displayFilePreview($id){
$selectedQuarter = self::getSelectedQuarter($id);
$files = self::getFiles($id);
//This line just grabs the directory of the next file
$nextFile = $files[0];
return response()->file(storage_path('app/'.$nextFile, "Cache-Control: 
no-cache"));
}

.HTML

<iframe id="file-processing-file-preview" src = "/fileProcess/displayFile/{{$selectedQuarter->id}}" width='400' height='300'></iframe>

爪哇语

$('#file-processing-file-preview')[0].contentWindow.location.reload(true);

我如何获得它,以便无论我以多快的速度循环浏览目录中的文件,iframe 都会始终显示当前选定的文件,而不是缓存并手动强制刷新和时间,然后再显示正确的文件?

想出了一个简单的解决方案。

在我加载 iFrame 的页面中,我简单地将当前日期和时间附加到 iFrame 的末尾,以强制它将其视为新请求。

<iframe id="file-processing-file-preview" src = "/fileProcess/displayFile/{{$selectedQuarter->id}}" width='400' height='300'></iframe>

<iframe id="file-processing-file-preview" src = "/fileProcess/displayFile/{{$selectedQuarter->id}}?time={{date('Y-m-d H:i:s')}}" width='400' height='300'></iframe>

现在每次都完美刷新

最新更新