【问题标题】:EJS - How to link anchor tag to the external websites?EJS - 如何将锚标签链接到外部网站?
【发布时间】:2018-06-20 05:44:35
【问题描述】:

我正在尝试导航到 ejs 模板引擎中的外部站点。但是,它将锚标记中的链接作为我的应用程序的路由之一,因此它打开链接如下:http://localhost:3000/www.youtube.com/watch?v=gtLJEhexrxY

   <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Results</title>
</head>
<body>
    <h1>Search results for <%=term %></h1>
    <% videos.forEach((video)=>{ %>
        <a href="www.youtube.com">Search</a>
        <a target=_blank href="www.youtube.com/watch?v=<%=video["id"]["videoId"]%>">
        <img src="<%=video["snippet"]["thumbnails"]["medium"]["url"]%>" alt="">
        </a>
            <div>

                <h3><%=video["snippet"]["title"]%></h3>
                <h4><%=video["snippet"]["publishedAt"]%></h4>
                <p><%=video["snippet"]["description"]%></p>
            </div>
        <br>
    <% }) %>
</body>
</html>

我想导航到 youtube.com,但它正在导航到 localhost:300/www.youtube.com

【问题讨论】:

  • 确保在外部链接前面添加http://!否则它是一个内部链接!

标签: node.js ejs viewengine


【解决方案1】:

解决了。我在开头添加了 http:// 前缀。感谢ngearing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2012-11-22
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多