I'm building a Chrome Extension, and I'm having some trouble adding an event listener. I want to add it to a button within the popup.
Here's the JS -
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('checkButton').onclick = grabLinks;
});
And here's the popup HTML -
<!DOCTYPE html>
<html>
<head>
<script src="background.js"></script>
</head>
<body>
<h3>Duplink</h3>
<p>Check if a link is already on this page.</p>
<form>
URL: <input id="URL" type="text" name="URL"><br>
<input id='checkButton' type="submit" value="Submit">
</form>
<p>Link is:<span id="message"></span></p>
</body>
</html>
Also, here's the manifest.json just in case -
{
"name": "Duplink",
"version": "1.0",
"description": "Check for duplicate links on DotDash sites",
"manifest_version": 2,
"background": {
"scripts": [
"background.js",
"popup.js"],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_title": "Duplink"
},
"permissions": [
"activeTab",
"storage"
]
}
When I unpack the extension, I get this error. - Error in event handler: TypeError: Cannot set property 'onclick' of null
Then it keeps repeating this error over and over again. - Uncaught TypeError: Cannot read property 'addListener' of undefined