简单 Chrome 扩展 returns 用户在警报中的输入
Simple Chrome Extention that returns the users input in an alert
这个扩展的 objective 是我可以在我的扩展中输入一些东西,按提交,然后提醒显示我的输入。
在我的 popup.html:
<form id="form" onsubmit="return false;">
<input type="text" id="userInput" />
<input type="submit" onclick="othername();" />
</form>
manifest.json:
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
},
和 content.js:
alert("test");
function othername() {
var input = document.getElementById("userInput").value;
alert(input);
};
出现 "test" 警报,所以我知道他的代码是 运行,但是当我输入一个值并按提交时,我没有看到弹出窗口。任何帮助将不胜感激。
您不能从HTML调用函数。
尝试在 JavaScript 中添加 click 事件侦听器。
document.getElementById('clickbutton').addEventListener('click', function() {
alert('hello ' + document.getElementById("userInput").value);
});
为此,我刚刚创建了一个新的 Chrome 扩展。
看看:
https://github.com/aldi/alert-input-chrome-extension
这个扩展的 objective 是我可以在我的扩展中输入一些东西,按提交,然后提醒显示我的输入。
在我的 popup.html:
<form id="form" onsubmit="return false;">
<input type="text" id="userInput" />
<input type="submit" onclick="othername();" />
</form>
manifest.json:
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
},
和 content.js:
alert("test");
function othername() {
var input = document.getElementById("userInput").value;
alert(input);
};
出现 "test" 警报,所以我知道他的代码是 运行,但是当我输入一个值并按提交时,我没有看到弹出窗口。任何帮助将不胜感激。
您不能从HTML调用函数。 尝试在 JavaScript 中添加 click 事件侦听器。
document.getElementById('clickbutton').addEventListener('click', function() {
alert('hello ' + document.getElementById("userInput").value);
});
为此,我刚刚创建了一个新的 Chrome 扩展。
看看:
https://github.com/aldi/alert-input-chrome-extension