无法使用onclick()事件触发alert()弹出
代码:
的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+ " )");
}
答案 0 :(得分:4)
请勿在Chrome扩展程序中使用内联Javascript。
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);