首页 > 解决方案 > 允许使用 node Express 进行跨域页面访问

问题描述

我正在尝试使用 iframe 在我的开发环境中访问跨域页面。

这是 Express js 在 http://localhost:5000 提供的主机页面。它有一个嵌入式 iframe,它试图访问在 http://localhost:3000 上运行的 React 应用程序。

<!DOCTYPE html>
<html>
<body>
    <h1>Host Page</h1>

    <iframe
        id="child"
        src="http://localhost:3000"
        scrolling="no"
        sandbox="allow-popups allow-scripts allow-same-origin"
        style="width: 1px; min-width: 100%; border-width: 0;"
    ></iframe>
</body>
</html>

但是,当此页面出现时,iframe 显示以下错误:

SecurityError: 阻止了来源为“http://localhost:3000”的框架访问跨域框架。

使这项工作最简单的方法是什么?这只是为了我的本地开发 - 没有任何安全问题!

标签: node.jsexpressiframecross-domain

解决方案


推荐阅读