Search code examples
javascriptfileunicodeemoji

emoji(🫀) in a file to html with js


i have a file:t.js which contains,

s='🫀';

then i open/view index.html, which contains,

<script src='t.js'></script>
<body>
<script>
document.write(s);
</script>  

but my output is,

🫀

so i tried doing something with these

btoa(unescape(encodeURIComponent('🫀')));

from here, still no difference at all.

so, is there a way to display 🫀 from my file, without using any external packages/libraries like js-base64 ?


Solution

  • added charset='utf-8' to the script tag's attributes

    <script src='t.js' charset='utf-8'></script>
    <body>
    <script>
    document.write(s);
    </script>  
    

    & worked...

    now its output is,

    🫀