Reputation: 9154
How do I insert a smiley in the HTML programatically? I want to know the logic as how does it exist along with text? Is it a styled ASCII character or something? thanks in advance.
Upvotes: 6
Views: 22649
Reputation: 543
This code can post table like above into your page
window.addEventListener(
'load',
() => {
var txt, tr, td, table = document.createElement('table');
for (var i = 0; i < 65536; i++) {
tr = document.createElement('tr');
td = document.createElement('td');
txt = document.createTextNode(i);
td.appendChild(txt);
tr.appendChild(td);
td = document.createElement('td');
txt = document.createTextNode('\\u' + i.toString(16));
td.appendChild(txt);
tr.appendChild(td);
td = document.createElement('td');
txt = document.createTextNode(String.fromCharCode(i));
td.appendChild(txt);
tr.appendChild(td);
table.appendChild(tr);
}
document.body.appendChild(table);
}
);
Be careful, it takes about 300ms for me :)
Upvotes: 0
Reputation: 408
There are many UTF-8 Miscellaneous Symbols are available in HTML.
Check out Below
Upvotes: 2
Reputation: 1803
Insert ☺
into an html document to render a smiley.
Comes out like this: ☺
It renders like this because it is a unicode character (See http://en.wikipedia.org/wiki/Smiley)
Upvotes: 16
Reputation: 10848
To be short, the smiley is just an image. You can store it on your server, and insert to html at client by javascript.
You may look at TinyMCE. They do exactly what you want, and open source: http://tinymce.moxiecode.com/
Upvotes: 0
Reputation: 1346
Hold down shift and push the :; button, then while holding down the shift key, push 0. Congrats, you've created your first smiley.
Humor aside, there are a few smiley characters that can be found in the ASCII character set. This page lists them. In most HTML message boards/emails, however, the software replaces typed smiley faces with emoticon images.
Hello world <img src="smileyface.png" alt="smiley face" />!
Upvotes: 2
Reputation: 23794
Assuming you mean smilies as found in various forums, you simply replace the ASCII smiley with a HTML img
element on the server side. The output will look like this:
<p>This is a paragraph <img src="wink.png" alt=";)"></p>
Most of the time this is achieved using e.g. the PHP str_replace
function.
Upvotes: 6