mihsathe
mihsathe

Reputation: 9154

Inserting smiley into the HTML

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

Answers (6)

Wera
Wera

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

Roshan Padole
Roshan Padole

Reputation: 408

There are many UTF-8 Miscellaneous Symbols are available in HTML. Check out Below enter image description here

Upvotes: 2

Carrotman42
Carrotman42

Reputation: 1803

Insert &#x263A 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

Ho&#224;ng Long
Ho&#224;ng Long

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

Vic
Vic

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

You
You

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

Related Questions