我似乎无法让这个工作。我找了答案,但似乎没有什么能帮助我。我有一个工作版本作为HTML页面,但我不能让它作为扩展工作。这是我的第一次延期,所以如果我做错了,请通知我。
的manifest.json:
{
"manifest_version": 2,
"name": "ROBLOX User-Profile Finder",
"description": "Find any user's profile by typing in their name.",
"version": "1.0",
"permissions": [
"<all_urls>"
],
"browser_action": {
"default_icon": "Icon.png",
"default_popup": "Popup.html"
}
}
Popup.html:
<!DOCTYPE html>
<html>
<head>
<script>
var link="http://roblox.com/user.aspx?username=";
function Submit(user) {
window.open(link.concat(user));
}
</script>
</head>
<body>
<p>Type in the roblox username:</p>
<input type="text" id="username" value="">
<button type="button" onclick="Submit(window.getElementById('username').value)">Go to Profile!</button>
</body>
</html>
这是什么问题?我想我错过了一些东西,因为我通常用Lua编程,而不是JavaScript。
解决:问题是我在中间制作脚本,我一直在寻求帮助,问题是引号和其他一些小错误的简单错误。如果有人感兴趣,这是完成的脚本:
的manifest.json:
{
"manifest_version": 2,
"name": "ROBLOX User-Profile Finder",
"description": "Find any user's profile by typing in their name. Note: Not created by roblox.",
"version": "1.0",
"permissions": [
"<all_urls>"
],
"browser_action": {
"default_icon": "Icon.png",
"default_popup": "Popup.html"
}
}
Popup.html:
<!DOCTYPE html>
<html>
<head>
<p>Type in the roblox username:</p>
<input type="text" id="username" value="">
<button type="button" id="Button">Go to Profile!</button>
</head>
<body>
<script src="Script.js"></script>
</body>
</html>
的script.js:
var link="http://roblox.com/user.aspx?username=";
function Submit() {
window.open(link.concat(document.getElementById("username").value));
}
document.getElementById('Button').addEventListener("click", Submit);
答案 0 :(得分:2)
首先,下次您想要使用开发者工具(F12)并转到控制台选项卡查看错误。
现在,针对您的具体问题,您无法在Chrome扩展程序中运行内联代码。
这不起作用:
<button type="button" onclick="Submit(window.getElementById('username').value)">Go to Profile!</button>
您需要编写外部.js文件并将按钮的所有事件绑定放在那里。因此,在此过程结束时,您的.js文件将为:
function myClickFunction() {
//click logic goes here
}
document.getElementById('myButton').addEventListener("click", myClickFunction);
你的.html看起来像这样:
<button type="button" id="myButton">Go to Profile!</button>