Greasemonkey:设置表单值在 Firefox 中不起作用
这在 Chrome 下完美运行,但在 Firefox 中,直到我第二次在页面上点击“提交”后,字段才会填充(在第一次告诉我无效的用户/密码后返回)。我缺少什么?
这是我的 Greasemonkey 脚本代码:
document.getElementById('loginBtn').addEventListener('click',
function (event) {
document.getElementById('serverLogin').selectedIndex = "2";
document.getElementById('usernameLogin').value = "username";
document.getElementById('passwordLogin').value = "password";
document.getElementById('loginForm').action = 'urltosubmit';
location.href="javascript:(function(){ document.forms['loginForm'].submit(); })()";
},true);
This works flawlessly under Chrome, but in Firefox the fields don't populate until the SECOND time I hit submit on the page (after it comes back from the first time telling me invalid user/pass). What am I missing?
This is my code for the Greasemonkey script:
document.getElementById('loginBtn').addEventListener('click',
function (event) {
document.getElementById('serverLogin').selectedIndex = "2";
document.getElementById('usernameLogin').value = "username";
document.getElementById('passwordLogin').value = "password";
document.getElementById('loginForm').action = 'urltosubmit';
location.href="javascript:(function(){ document.forms['loginForm'].submit(); })()";
},true);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该发布表单代码,但问题很可能是事件传播。
将函数更改为:
You should post your form code, but the problem is most likely, event propagation.
Change the function to:
或者也许...
or maybe...