3

connect-flash メッセージのテキストにリンクを含めたい:

JS

req.flash("registerMessage", "Sorry, the User ID you chose is already in use. Please choose another. If you have already registered and need assistance logging in, <a href=\"http://www.example.com/support/\">contact support</a>");

EJS

<% if (message.length > 0) { %>
  <div class="alert alert-danger"><%= message %></div>
<% } %>

結果

<div class="alert alert-danger">Sorry, the User ID you chose is already in use. Please choose another. If you have already registered and need assistance logging in, &lt;a href=&quot;http://www.example.com/support/&quot;&gt;contact support&lt;/a&gt;.</div>

メッセージにリンクを表示できるように、Flash が HTML 文字をエスケープするのを防ぐ方法はありますか?

4

1 に答える 1

6

使用できます:

<%- message %> 

エスケープされていない HTML を出力する

于 2014-10-12T21:21:10.580 に答える