Reputation: 31
I want to dynamically add a meta tag to my HTML <head>
after the page is loaded. I found some solutions to add a meta tag, but the all only work while the page is loading. After the page is loaded once, the don't work anymore.
document.head.innerHTML += '<meta content="test" property="test"/>';
That's what I tried. But as I said above this does not work is the page is already loaded.
Is there a solution for this? Maybe something like reload the page?
Upvotes: 1
Views: 1833
Reputation: 485
function ready() {
document.head.innerHTML += '<meta content="test" property="test"/>';
}
document.addEventListener("DOMContentLoaded", ready);
Maybe event DOMContentLoaded is the solution, source: https://javascript.info/onload-ondomcontentloaded.
Upvotes: 1