问题描述
在新的chrome版本中,我收到此错误:
In new chrome versions I got this error:
Window is not allowed to navigate Top-frame navigations to data URLs
图像看起来像这样(URL中包含数据):
The image looks like that (contains data in the url):
我真的需要在新标签页中打开它. iFrame解决方案不相关
I really need to open it in a new tab. The iFrame solution isn't relevant
推荐答案
一个JavaScript解决方案:
A javascript solution:
var newTab = window.open();
newTab.document.body.innerHTML = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" width="100px" height="100px">';
有很多方法可以更改window.open()的行为方式,请查看文档.创建一些css/html来模仿Chrome在新标签页中显示图像的方式也不难.出于安全原因,已删除了加载data:
URL的功能,因此,如果您正在寻找一种执行此操作的方法,那么您将很不走运.
There's a lot of ways that you can change the way window.open() behaves, check out the documentation. It also shouldn't be hard to create some css/html that will mimic the way Chrome displays images in new tabs. The ability to load data:
URLs was removed for security reasons, so you're out of luck if you're looking for a way to do that.
这篇关于在新选项卡中打开的Base64图像:不允许窗口导航到数据URL的顶级框架导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!