这可能是因为在iframe的src属性中使用blob URL时,浏览器可能会出于安全考虑阻止加载。浏览器认为iframe中的内容来自不同的源,可能存在安全隐患。

要解决这个问题,你可以尝试将blob URL转换为可信任的URL,例如使用createObjectURL方法创建一个Blob对象的URL。以下是一个示例代码:

// 通过fetch获取blob数据
fetch('blob:http://localhost:8080/e3d44e31-8006-4efa-8c06-c26ba4cc0700')
  .then(response => response.blob())
  .then(blob => {
    // 创建blob的URL
    const url = URL.createObjectURL(blob);
    
    // 将blob URL设置为iframe的src属性
    const iframe = document.querySelector('iframe');
    iframe.src = url;
  });

这样做将确保浏览器信任blob URL,并能够正常加载和显示内容

iframe embed元素 src=blobhttplocalhost8080e3d44e31-8006-4efa-8c06-c26ba4cc0700显示空白但把blobhttplocalhost8080e3d44e31-8006-4efa-8c06-c26ba4cc0700直接放在地址栏中能正常显示

原文地址: http://www.cveoy.top/t/topic/isrW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录