我无法用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 + ")");
}
{
"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"
}
}
<html>
<head></head>
<body>
<div class="plus" onclick="popup()"></div>
<script src="inline.js"></script>
</body>
</html>
function popup() {
var link = document.URL;
alert("This is the link: (" + link + ")");
}
不要在Chrome扩展中使用内联JavaScript代码。
HTML:<div class="plus"></div>
<script src="inline.js"></script>
JavaScript: function popup(e) {
var link = document.URL;
alert("This is the link: (" + link + ")");
}
var plusBtn = document.querySelector('.plus');
plusBtn.addEventListener('click', popup);