You can use document.createElement
with appendChild
and insertBefore
, to insert do this you can do this:
//Esta função é mais rapida que usar window.onload
function readyDom(callback) {
if (/^(interactive|complete)$/i.test(document.readyState)) {
callback();
} else {
document.addEventListener("DOMContentLoaded", callback);
}
}
//vai inserir dentro do head antes do </head>
readyDom(function() {
var navbar = document.createElement("link");
navbar.rel = "stylesheet";
navbar.type = "text/css";
navbar.href = "http://cdn.grupospotlight.com/nav/navbar.css";
document.head.appendChild(navbar);
});
//vai no <body>, antes de qualquer elemento
readyDom(function() {
var ulnav = document.createElement("ul");
ulnav.className = "spot-nav";
ulnav.innerHTML = '<li class="left spot-logo">' +
'<a class="spot-a"><div class="spot-logo"></div></a>' +
'</li>' +
'<li class="right">' +
'<a class="spot-a" href="http://www.grupospotlight.com/" target="_blank">WWW.GRUPOSPOTLIGHT.COM</a>' +
'</li>';
document.body.insertBefore(ulnav, document.body.firstChild);
});
If you need a delay use setTimeout
:
//vai no <body>, antes de qualquer elemento
readyDom(function() {
var segundos = 3; //3 segundos
setTimeout(function() {
var ulnav = document.createElement("ul");
ulnav.className = "spot-nav";
ulnav.innerHTML = '<li class="left spot-logo">' +
'<a class="spot-a"><div class="spot-logo"></div></a>' +
'</li>' +
'<li class="right">' +
'<a class="spot-a" href="http://www.grupospotlight.com/" target="_blank">WWW.GRUPOSPOTLIGHT.COM</a>' +
'</li>';
document.body.insertBefore(ulnav, document.body.firstChild);
}, 1000 * segundos);
});
I recommend you study on DOM: