last day (14 days later) » 

12:49 PM
0
Q: jQuery display only pure HTML in HTML excluding htmlentities

JasI'm currently displaying posts from my database, and this is an example of the 'message' field in my database. The Alice hyperlink links to the user's profile, while the ?&lt; etc. are all HTML specified by the user themselves. <a href="/profile/Alice">Alice</a> Alice, you there?&lt;strong&gt;ar...

 
I would just serve it straight up! jsfiddle.net/kgs4w62q
 
Jas
@RobSchmuecker I'm using .append() and they'll display as html anyway.
 
Jas
@RobSchmuecker This is weird. jsfiddle shows it working the way I want it to be, but when I run it on my site, it's showing the user-inputted HTML. Any idea why?
 
Show us the code you are using exactly.
 
Jas
12:49 PM
@RobSchmuecker I've included my existing js code. Sorry about that.
ooh chats work here?! heyhey
 
You can try and console.log(this.content) and see what's actually being sent? Also try a console.log(data)
 
Jas
OK one sec.
<a href="/user/Jay">Jay</a> <strong>lol</strong>
feed.js:25 [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
hmm sorry it seems like the data isn't in entities
but I did do a htmlentities() for the user-input
 
AH ok, perhaps there's something in the get function that is autmatically encoding it?! have a look in the network tab of your debugger and see the raw response you're getting from the server
 
Jas
{"content":"<a href=\"\/user\/Jason\">Jason<\/a> &lt;strong&gt;test2&lt;\/strong&gt;"}
 
OK - so it's coming through in JSON and htmlentities ... now let's have a quick look.
 
Jas
1:04 PM
and sorry to take up your time!
 
Looks to be working fine here again?! jsfiddle.net/kgs4w62q/2 which version of jQuery you using?
 
Jas
1.11.2
 
Hmm, just ried the fiddle with 1.11.0 and it's also working.... now looking into the append method.
what browser/debugger you using?
 
Jas
Chrome.
Oh I think I've found the problem
 
what do you think it is?
 
Jas
1:08 PM
I had a piece of code below (that converts youtube links to youtube embeds)
$('.feed-content').contents()
.filter(function(){
return this.nodeType === 3;
})
.map(function(index, text){
$(text).replaceWith(
text.textContent.replace(/(?:http:\/\/)?(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<p><div class="embed-responsive embed-responsive-16by9"><iframe width="560" height="315" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe></div>').replace(/(?:http:\/\/)?(?:www\.)?(?:vimeo\.com)\/(.+)/g, '<iframe src="//player.vimeo.com/video/$1" width="200" height="100" frameborder="0" webkitallowfullscreen mozallowful
somehow after removing that, it's working as expected...
 
strange!
see nothing in there that should cause it to change the entities?
 
Jas
I'm not sure! I guess I can just remove it for the time being.
 
Maybe there's something to do with textContent oh well glad you're sorted!
 
Jas
Last question, you guys dedicate so much time on stackoverflow
what's your drive behind that?! are you even doing anything atm? (like busy at work)
 
;-)
Yes I work for myself from home! I choose when I work! So yes i'm working at the moment but sometimes do a stint on SO! It's a great differentiator when people come to hiring you and you have a decent SO profile in my opinion too.
You also learn a lot.
 
Jas
1:15 PM
ahh I see
Well Thanks Mr Rob. Till we meet again!! (I come on here a lot - to ask stupid questions D:)
P.S. I'm currently checking out your website
 
Haha - go well! Godspeed! - yeah that's more of a scrapbook of some of my thoughts! You know where to find me!
 
Jas
Please come to my rescue again, if I need help! - but this isn't my real account... I just feel really dumb asking these questions
so I made this account to hide my stupidity away!
hahaha ok have a great weekend!
 
Ah ok! What's your real account?!
 
Jas
It's just as dumb as this. Don't worry about it!
OK Thanks again!
 
It's also nice to help people. Life's better that way, to give more than to take ;-) Enjoy your weekend!
 
Jas
1:18 PM
o/
how do I give you a +?
 
Forget about it!
 
Jas
I insist!
 
Buy me a beer when our paths cross again!
Ciao
 
Jas
OK I'll buy you a nice Tiger beer (Singaporean beer) the next time
seeyaa
 

last day (14 days later) »