javascript - 按钮上的 Google Apps 脚本 + React Web 应用程序错误提交“不安全的 Javascript 尝试...框架正在尝试导航顶级窗口”
问题描述
我正在使用这个库(enuchi/React-Google-Apps-Script)用 React 构建一个应用程序脚本 Web 应用程序。我正在使用一个按钮来处理表单数据。当用户单击提交时,我运行一个函数来处理数据。我实际上并没有在任何地方发布数据,它保留在应用程序中。
在按钮上使用 type="submit" 时,我收到以下错误:
Unsafe JavaScript attempt to initiate navigation for frame with origin 'https://docs.google.com' from frame with URL 'https://localhost:3000/taxonomy-impl.html'. The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.
起初我以为是提交按钮的页面刷新行为触发了这个,所以我event.preventDefault()
在按钮上测试了一个,但没有奏效。
<Button type="submit" onSubmit={(event)=>{event.preventDefault()}}>Submit Form</Button>
我已经能够通过删除按钮 type="submit" 并运行我的函数来解决这个问题onClick
,但是如果我这样做,我会丢失自动 HTML5 表单验证。有谁知道我可以如何解决这个错误?谢谢!
解决方案
在aditya的评论中回答!Onsubmit 应该在表单而不是按钮上。
推荐阅读
- flutter - StreamBuilder 可以在构建方法之外吗?
- php - Wordpress 简码 - 基于全球产品交付周期的日期
- python - Python:当字典具有错误值时,“NoneType”对象没有属性“键”
- reactjs - 错误:TypeError:无法读取未定义的属性“图像”
- angular - Angular 制作安全登录/注册页面
- javascript - 续集 findAndCountAll 分页问题
- c# - 如何删除种子而不会对数据库产生任何影响?
- javascript - 在 sequelize.js 中使用 faker 种子:基于其他列值的列值
- swift - 如何覆盖 UICollectionViewCells 的默认位置?
- django - Django Rest Framework 未验证所有模型的字段