在新选项卡中打开的Base64图像:不允许窗口导航到数据URL的顶级框架导航 [英] Base64 Image open in new tab: Window is not allowed to navigate Top-frame navigations to data URLs

查看:204
本文介绍了在新选项卡中打开的Base64图像:不允许窗口导航到数据URL的顶级框架导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的chrome版本中,我收到此错误:

In new chrome versions I got this error:

Window is not allowed to navigate Top-frame navigations to data URLs

图像看起来像这样(URL中包含数据): data:image/png;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAA...

The image looks like that (contains data in the url): data:image/png;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAA...

我真的需要在新标签页中打开它. 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()的行为方式,请查看

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的顶级框架导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆