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";
Related Contents:
- How can I change an element’s class with JavaScript?
- Retrieve the position (X,Y) of an HTML element
- How to make JavaScript execute after page load?
- Parse an HTML string with JS
- How to resolve the C:\fakepath?
- Converting HTML string into DOM elements?
- How to append text to a “?
- Check if an element contains a class in JavaScript?
- What is the most efficient way to create HTML elements using jQuery?
- Browser detection versus feature detection
- How to correctly iterate through getElementsByClassName
- Changing CSS Values with Javascript
- How do I create a link using javascript?
- Get next / previous element using JavaScript?
- Get selected option text with JavaScript
- Finding line-wraps
- Find the closest ancestor element that has a specific class
- What is offsetHeight, clientHeight, scrollHeight?
- Why is the value of my input always empty if I store it in a variable?
- How can I get the DOM element which contains the current selection?
- Why are duplicate ID values not allowed in HTML?
- Difference between Node object and Element object?
- How to show Page Loading div until the page has finished loading?
- How do I replace text inside a div element?
- Can I load an entire HTML document into a document fragment in Internet Explorer?
- What is innerHTML on input elements?
- HTML “overlay” which allows clicks to fall through to elements behind it [duplicate]
- Pass mouse events through absolutely-positioned element
- How to convert a DOM node list to an array in Javascript?
- JavaScript DOM: Find Element Index In Container
- Is innerHTML asynchronous?
- JavaScript get element by name
- What’s standard behavior when element is clicked? Will it submit the form?
- How to iterate through all attributes in an HTML element?
- Difference between Element.value and Element.getAttribute(“value”)
- How do you listen / detect changes to an input value – when the input value is changed via javascript?
- How to prevent an HTTP request just for a favicon?
- Adding images to an HTML document with JavaScript
- Can I apply CSS to the elements within an iframe?
- How do I put codes from jsfiddle.net into my website?
- Why is the variable holding the input value always logged as empty?
- Changing the order of elements
- contentDocument for an iframe
- Focus Input Box On Load
- Why does getElementById not work on elements inside the document element? [duplicate]
- Trying to set a span element equal to a variable value in a JS Rock, Paper, Scissors Game
- a way to check validity of HTML5 forms?
- Why does JavaScript navigator.appName return Netscape for Safari, Firefox and Chrome?
- Replacement for deprecated `keypress` DOM event
- Open new window without focus on it [duplicate]