我正在开发 Flask 网络应用程序。它有两个并排的 iframe 并访问一个 csv 文件。该文件包含 url,通过使用 selenium .page_source(),将使用 srcdoc 加载到 iframe 中。页面源代码使用beautiful soup 4编辑后转成字符串发送给前端。
我现在面临的问题是,当我打开应用程序(本地或虚拟机上托管的版本)时,有时我会被重定向到网址栏中带有“about:srcdoc”的空页面。虽然它不会 100% 发生,但它发生的频率足以成为一个问题。
GitHub 代码库:https://github.com/MohamedMoustafaNUIG/AnnotatorVM
flask应用是annotator.py,从根加载的页面是app/templates/index.html和app/templates/base.html
index.html 中的代码片段
<div class="row" style="width: 100%; height: 80%; min-height: 600px;">
<p align="center">Annotated Origins: {{fpo}} / {{tpo}} for this page and {{fto}} / {{tto}} in total</p>
<div class="column left" style="width:50%; position: relative; display: inline-block; margin: 0; border: 0; padding: 0;">
<h4><a id="cLink" href="{{t3}}" target="_blank">Fact Checking Article: </a></h4>
<iframe id="cframe" style="display: block" width="100%" height="100%" srcdoc="{{t1}}"></iframe>
</div>
<div class="column right" style="width:50%; position: relative; display: inline-block; margin: 0; border: 0; padding:0;">
<h4><a id="oLink" href={{t4}} target="_blank">Origin Candidate: </a></h4>
<iframe id="oframe" style="display: block" width="100%" height="100%" srcdoc="{{t2}}"></iframe>
</div>
</div>
有没有人遇到过类似的问题?它不需要在使用 flask 时,我只是想了解重定向到“about:srcdoc”背后的逻辑。有什么建议吗?提前谢谢你:)
编辑:什么都没有?我不可能是第一个遇到这个问题的人。
最佳答案
似乎某些页面显示在 iframe 中,其中将父页面(我的应用程序)重定向到 about:srcdoc url。通过对两个 iframe 进行沙盒处理并仅限制顶部导航来解决此问题。
关于javascript - 当请求索引(根路径)时,Flask 应用程序重定向到空的 "about:srcdoc"页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56544507/