EJS-如何将定位标记链接到外部网站?

时间:2018-06-20 05:44:36

标签: node.js ejs viewengine

我正在尝试导航到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

1 个答案:

答案 0 :(得分:0)

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