Search code examples
htmlwebfavicon

Alternatives to insert a FAVICON?


I have a problem with the advanced website manager that I am currently using, and that is that it does not allow me access to the HEAD tag, therefore I cannot set a FAVICON on the website. I would like to know if there are other alternatives to insert a favicon on the website without changing the HEAD code. The website lacks the appropriate tag to insert a favicon.

I know it can be a little crazy, but thanks anyway...


Solution

  • You will be able to insert a <link rel="favicon"> by adding a short javascript just before the closing body tag (</body>):

    <script>
    let faviconLink = document.createElement('link');
    
    faviconLink.setAttribute('rel', 'favicon');
    faviconLink.setAttribute('href', '/path/to/favicon.svg');
    faviconLink.setAttribute('type', 'image/svg+xml');
    
    document.head.appendChild(faviconLink);
    </script>
    

    The example above uses an SVG favicon, but you can just as easily use another image format with another MIME type:

    • PNG: type="image/png"
    • GIF: type="image/gif"