Why not?
var link = document.querySelector("link[rel~='icon']");
if (!link) {
link = document.createElement('link');
link.rel="icon";
document.getElementsByTagName('head')[0].appendChild(link);
}
link.href="https://stackoverflow.com/favicon.ico";
More Related Contents:
- Do DOM tree elements with IDs become global properties?
- How to make JavaScript execute after page load?
- How do I programmatically set the value of a select box element using JavaScript?
- Check if an element contains a class in JavaScript?
- How to correctly iterate through getElementsByClassName
- Appending HTML string to the DOM
- Chrome extension – retrieving global variable from webpage
- innerText vs innerHTML vs label vs text vs textContent vs outerText
- Why is the value of my input always empty if I store it in a variable?
- Best Practice: Access form elements by HTML id or name attribute?
- Difference between Node object and Element object?
- Why are duplicate ID values not allowed in HTML?
- HTML “overlay” which allows clicks to fall through to elements behind it [duplicate]
- How to convert a DOM node list to an array in Javascript?
- JavaScript get element by name
- Is there a DOM event that fires when an HTML select element is closed?
- Difference between Element.value and Element.getAttribute(“value”)
- How to prevent an HTTP request just for a favicon?
- Why is the variable holding the input value always logged as empty?
- HTML DOM: Which events do not bubble?
- How do I put codes from jsfiddle.net into my website?
- Screen Scraping from a web page with a lot of Javascript [closed]
- Attach event listener through javascript to radio button
- window.getSelection() gives me the selected text, but I want the HTML
- Is there a flexible way to modify the contents of an editable element?
- a way to check validity of HTML5 forms?
- Open new window without focus on it [duplicate]
- Is there a way to get innerText of only the top element (and ignore the child element’s innerText)?
- Images failing to load in IE with DOM: 7009 error (unable to decode) in console
- Why is iframe.contentWindow == null?