You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

p5.js iframe无法正常显示,报Uncaught (in promise) DOMException错误

问题描述

在HTML文件中插入p5.js的iframe标签后无法正常显示内容,页面仅显示“loading...”提示,控制台报错:Uncaught (in promise) DOMException: The user aborted a request。使用的HTML代码如下:

<iframe allowfullscreen src="https://editor.p5js.org/AlieNiT/full/DTFXjG_6a"></iframe>
解决方法
  • 检查项目隐私设置:登录p5.js编辑器,打开对应项目(DTFXjG_6a),确认项目权限设置为公开(Public)。私有项目会限制外部iframe嵌入访问,导致加载失败。
  • 补充iframe必要属性:为iframe添加宽高属性及安全沙箱配置,调整后的代码示例:
    <iframe 
      allowfullscreen 
      width="800" 
      height="600" 
      sandbox="allow-scripts allow-same-origin allow-popups"
      src="https://editor.p5js.org/AlieNiT/full/DTFXjG_6a"
    ></iframe>
    
    沙箱属性sandbox会放宽浏览器的安全限制,允许脚本执行和同源资源访问,避免加载被拦截。
  • 清除浏览器缓存/使用无痕模式:浏览器缓存可能导致资源加载异常,清除缓存后重新加载页面,或直接用无痕模式打开测试。

内容的提问来源于stack exchange,提问作者Seyed Alireza Hashemi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 17:22:46