按钮点击不工作在谷歌扩展
button click not working in google extension
hi我正在制作chrome扩展,它重定向到我的网站并自动填充密码。我无法提交按钮点击事件。
manifest.json // manifest json code
{
"name": "z",
"version": "0.1",
"description": "z",
"background": {
"scripts":["redirect.js"]
},
"manifest_version": 2,
"permissions": [
"http://Abcd:90/Login.aspx"
],
"browser_action": {
"default_icon": {
"19": "icon.png" //you have to put an image icon.png in to the folder.
},
"default_title": "Redirect" //optional
}
}
----------------------------redirect.js------------------
//尝试
chrome.browserAction.onClicked.addListener(function(tab) {
debugger
chrome.tabs.create({ url: "http://Abcd:90/Login.aspx" });
hello();
});
function hello() {
debugger
var myUsername = 'username';
var myPassword = 'password';
// find the fiends in your lo
document.getElementsByName('ctlLogin$UserName').value = myUsername;
document.getElementsByName('ctlLogin$Password').value = myPassword;
var link = document.getElementById('ctlLogin_LoginButton');
link.addEventListener('DOMContentLoaded', function () { // unable to perform click.
var link = document.getElementByName('ctlLogin$LoginButton');
// onClick's logic below:
alert(link);
link.addEventListener('click', function () {
hellYeah('xxx');
});
});
//也试过这个
var link = document.getElementById('ctlLogin_LoginButton');
link.addEventListener('click', function () {
alert('gg');
});
}
//还有这个
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('ctlLogin_LoginButton').addEventListener('click', showalert, false);
}, false);
function showalert() {
alert("you just pressed the button");
}
尝试以下片段:
在XML:中
<input id="ctlLogin_LoginButton" type="submit" value="Submit">
一旦加载了弹出文档主体,这个脚本就应该将事件附加到元素上。
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("ctlLogin_LoginButton").addEventListener("click", hello);
});
你也可以检查这个相关的问题:点击Chrome扩展不工作
希望这能有所帮助!
将处理程序附加到任何现有元素
$(document).on("click","#ctlLogin_LoginButton",function(e) {
console.log("button clicked");
})
相关文章:
- 如何在谷歌开发者控制台上为firefox扩展创建oAuth项目
- 如何知道你右键点击谷歌chrome扩展是什么
- 对齐底部的DIV-谷歌Chrome扩展
- 谷歌扩展:如何在弹出窗口中按下按钮时在我的javascript文件中运行函数
- 列出谷歌浏览器中安装的所有扩展程序
- 浏览器扩展程序来跟踪我的谷歌活动
- 谷歌浏览器扩展程序画布图标
- 为什么我的谷歌浏览器扩展程序在谷歌浏览器版本 41.0.2272.89 中不起作用
- 如何缩小我的谷歌chrome扩展's的javascript文件
- 当弹出窗口关闭时播放声音文件(谷歌扩展)
- 谷歌Chrome扩展在用Javascript打开的弹出窗口中工作吗
- 基本的谷歌chrome扩展消息传递不起作用
- 按钮点击不工作在谷歌扩展
- AngularJS-谷歌Chrome扩展中的动态链接断开
- 谷歌扩展弹出窗口未显示
- 谷歌扩展:标签事件 - 更改窗口
- 如何在谷歌扩展中打开/关闭content_scripts
- 问题与谷歌扩展
- 得到下拉菜单在谷歌扩展弹出
- 没有找到谷歌扩展本地消息传递主机