【问题标题】:Express failing to load iframe contents from subdirectoryExpress 无法从子目录加载 iframe 内容
【发布时间】:2021-05-04 07:44:57
【问题描述】:

当我尝试使用 iframe 加载另一个(本地)网页时,express 无法加载 iframe 的内容

/index.html(加载器)

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>Not important</title>
    </head>
    <body>
        <iframe src="/pages/test.html" width="" height=""></iframe>
    </body>
</html>

main.js

const express = require("express");
const app = express();
const port = 7077;

app.use("/", express.static("public"));

app.listen(port, () => {
  console.log(`Server listening on port ${port}`);
});

Error:

Cannot GET /test.html

文件层次结构:

project folder
| main.js
| public
| | index.html
| | pages
| | | test.html
| | |_
| |_
|_

编辑添加:如果我直接在我的网络浏览器中加载/pages/test.html,那效果很好。只是在 iframe 中时。

编辑:没关系。是 Firefox 的问题,而不是我的代码(耶?)

【问题讨论】:

    标签: javascript node.js express http


    【解决方案1】:

    我试图重现你的问题,我认为你必须将你的 pages 文件夹放在 public 文件夹中,像这样:

    代码和你的一样

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多