javascript - 我想知道如何将 ejs 放入 iframe src 属性
问题描述
<iframe class="iframe-preview" width="100%" src="./views/main.ejs">
</iframe>
</body>
</html>
我想index.ejs
从node.js
和main.ejs
从打电话index.ejs
。屏幕上index.ejs
显示得很好,但main.ejs
继续下载...有没有办法ejs
在屏幕上显示iframe
?
解决方案
您不应该在 DOM 中使用 ejs,因为它是一种服务器端技术,因此 ejs 文件不也不应该在浏览器中可用。而是像这样使用它:
<iframe class="iframe-preview" width="100%" src="/main">
</iframe>
</body>
</html>
在哪里链接到“/ main”会打开你的路由器
router.get('/main',(req,res)=>{res.render('./views/main.ejs'})
并将您的页面返回到您想要的任何位置(如果您愿意,可以在 iframe 中)。
推荐阅读
- json - 带有json字符串的tqdm进度条卡住了
- solr - 索引 nutch 数据时出现 Solr 重复数据删除错误
- javascript - 获取mxGraph顶点所有对象数据
- amazon-dynamodb - 如果全局二级索引中的哈希和范围键相同,数据如何存储在 dynamo db 中
- node.js - 相同的图像未以快递方式上传
- javascript - @ApiImplicitQuery 招摇 - 无法配置“枚举”
- typescript - 打字稿:什么是“裸类型参数”
- c# - Asp.net 核心路由 ambiguousActionException
- amazon-web-services - AWS s3:如何快速列出某些对象
- angular - Angular 6 返回函数代码而不是结果