首页 > 解决方案 > 按钮上的 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 表单验证。有谁知道我可以如何解决这个错误?谢谢!

标签: javascriptreactjsgoogle-apps-scriptiframe

解决方案


在aditya的评论中回答!Onsubmit 应该在表单而不是按钮上。


推荐阅读