首页 > 解决方案 > 我想知道如何将 ejs 放入 iframe src 属性

问题描述

<iframe class="iframe-preview" width="100%" src="./views/main.ejs"> 
</iframe>

</body>
</html>

我想index.ejsnode.jsmain.ejs从打电话index.ejs。屏幕上index.ejs显示得很好,但main.ejs继续下载...有没有办法ejs在屏幕上显示iframe

标签: javascripthtmlnode.jsejs

解决方案


您不应该在 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 中)。


推荐阅读