iframe 在本地服务器上正常工作,但在生产服务器上无法正常工作
以前有人问过这样的问题,但这个人除了批评什么也没有,希望这里不会出现这种情况。
我有一个网站,允许企业将其菜单添加到我的网站,有些企业要求能够导入其他地方已经在线的菜单(pdf 或 jpg)。因此,我制作了一个表单,将 url 保存到数据库,然后在我网站上的 iframe 的 src 中使用该 url。
我对它进行了全部测试,它在我的本地计算机上运行良好(使用 Django 开发服务器)。当我将其同步到我的生产服务器并保存我正在测试的相同 URL 时,iframe 不加载任何内容。
我想这与尝试从另一台服务器读取单个文件有关,因为如果我将 url 设置为 google.com 或我的域名下的图像,它就会起作用。我能做些什么来解决这个问题吗?在我的数据库中存储 url 而不是 pdf 效率更高,因此这样做比将菜单上传到我的网站更受欢迎。
我认为这个问题不需要附加任何代码,但如果您想看一些代码,请让我听听。
谢谢
A question like this was asked before and the person got nothing but criticisms, hope this won't be the case here.
I have a website that allows a business to add their menu to my site, and some have requested to be able to import a menu (a pdf or jpg) that is already online elsewhere. So I made a form that saves a url to the db and then that url is used in the src of an iframe on my site.
I tested it all and it worked fine on my local machine (using Django development server). When I synced it over to my production server and saved the same url I was testing with, the iframe loads no content.
I imagine that it has something to do with trying to read an individual file from another server because it works if I make the url google.com or to an image that is under my domain name. Is there anything I can do to fix this? Storing a url instead of a pdf in my db is much more efficient so doing this way is preferred over uploading their menu to my site.
I don't think this question needs any code attached, but if you want to see some let me hear it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在测试的菜单可能具有
X-Frame-Options
响应标头设置。您将图像/pdf作为
iframe
上的src
而不是仅使用img
标签(或放置一个iframe
中的img
标记)?仍然不能保证适用于所有页面,因为某些网站会拒绝向外部页面提供媒体,但我怀疑这是您在这种情况下的问题。The menu you're testing with probably has the
X-Frame-Options
response header set.Is there a reason you're putting the image/pdf as the
src
on aniframe
instead of just using theimg
tag (or putting animg
tag inside youriframe
)? There's still no guarantee that will work for all pages, as some sites will refuse to serve media to an external page, but I suspect this is your problem in this case.