String for HTML

Asked

Viewed 1,109 times

0

Good afternoon, I’m not sure if that’s the most appropriate title...

I’m using Meteor and mongodb.

I have 2 input, one where I type the name of the site and the other I type the site "www.exemplo.com.br", which then in javascript I have the following:

var siteCad = '<a href="http://'+ site +'">' + nome + '</a>';

Then I insert the siteCad inside a MongoDB Collection. I would like to show all these links within a <.li> but what is happening is that it shows the whole text, from the <.a href... to the "dot and comma", I want to show the link directly, as if it were directly from html.

In short, I have html tags with properties filled in in mongoDB in string format and would like to move to html.

Does anyone have any example or reference that I can take a look at?

  • In general it is not a good idea to generate HTML using string concatenation as you are doing. You are vulnerable to Javascript injections (XSS) if the user puts html tags in the name or an "onhover" in the site field.

  • And why do you want to insert HTML into the database? Wouldn’t it be better to insert a record with the name and the site and generate the html later?

  • is what I’m thinking now, but I don’t know how to insert the site in href there in the html there, I’m starting the studies in Content actually. How would I set a variable in href?

  • If I try to do this: <a href={site}}>, it just doesn’t work.

1 answer

1

  • Good morning, thanks for the answer... I had already done so, the problem is that it did not work at first because I was doing <a href="http://" + {{siteCad}}... but after I did so as you said, it was right. Thanks!

  • You’re welcome! I’m happy to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.