I dont know if this is a good idea but I am trying to add a script using document.write in my HTML document that would add a script only if the browser is online.
<script>
var online = navigator.onLine;
if(online){
document.write("<script src='./api.js'></script>");
}
</script>
the thing is the browser is stoping at the first closing </script>
tag that is inside the document.write function, causing everything else to be interpreted as HTML ( ");
appears renedered in the html) , I know that I am doing something wrong but would like to know what