Ultra simple Chrome Extension doesn't addEventListener to button onclick event

前端 未结 1 1086
攒了一身酷
攒了一身酷 2020-12-17 17:22

So I\'m testing out creating a chrome extension. I understand that with Manifest v2 you can\'t have javascript in popup.html. So, I\'ve moved the javascript to a separate fi

相关标签:
1条回答
  • 2020-12-17 17:50

    Just remove window.onload:

    function myAlert(){
        alert('hello world');
    }
    
    document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('alertButton').addEventListener('click', myAlert);
    });
    
    0 讨论(0)
提交回复
热议问题