Chrome extension: onclick() event not triggering alert() popup [duplicate]

Unable to trigger alert() popup with onclick() event

code:

manifest.json:

{
"name": "Project",
"version": "1.0.0",
"manifest_version": 2,
"description": "Popup when website requires Log in",
"browser_action":{
    "default_icon":"icon_19.png",
    "default_popup":"Popup.html"
    }
}

Popup.html:

<html>
<head></head>
<body>
<div class="plus" onclick="popup()"></div>
<script src="inline.js"></script>
</body>
</html>

inline.js:

function popup() {
var link = document.URL;
alert("This is the Link : ( " +link+ " )");
}

Answers:

Answer

Don't use inline Javascript in a chrome extension.

HTML:

<div class="plus"></div>
<script src="inline.js"></script>

JS:

function popup(e) {
  var link = document.URL;
  alert("This is the Link : ( " +link+ " )");
}

var plusBtn = document.querySelector('.plus');
plusBtn.addEventListener('click', popup);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.