ana*_*99g 3 javascript event-handling google-chrome-extension dom-events google-chrome-app
我无法alert()通过onclick()事件触发弹出窗口。
{
"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"
}
}
Run Code Online (Sandbox Code Playgroud)
<html>
<head></head>
<body>
<div class="plus" onclick="popup()"></div>
<script src="inline.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
function popup() {
var link = document.URL;
alert("This is the link: (" + link + ")");
}
Run Code Online (Sandbox Code Playgroud)
不要在 Google Chrome 扩展程序中使用内联 JavaScript 代码。
HTML:
<div class="plus"></div>
<script src="inline.js"></script>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
function popup(e) {
var link = document.URL;
alert("This is the link: (" + link + ")");
}
var plusBtn = document.querySelector('.plus');
plusBtn.addEventListener('click', popup);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11702 次 |
| 最近记录: |