【发布时间】:2013-03-23 21:18:52
【问题描述】:
我无法使用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 + ")");
}
【问题讨论】:
-
不要使用任何内联代码,将其全部移动到外部文件中。这也包括
onclick。 -
@BeardFist 非常感谢。以及如何获取网站的网址?它只是显示 popup.html 的 url
-
你可以使用
chrome.tabs.query和active:true获取当前标签,然后使用tab.url获取url。
标签: javascript google-chrome-extension event-handling dom-events google-chrome-app