admin管理员组文章数量:1391955
I'm creating a GreaseMonkey script that will auto login to a page as long as the user has saved their username and password in the browser. It's pretty simple, it's just checks to make sure that the username field and the password field are not blank and then it clicks the login button automatically.
Every now and then I was running in to an issue to where it didn't login. The page loaded and just sat there. I assumed it was simply due to the page not being fully loaded when the check of the username and password fields were done.
Because of this, I added this to my script.
window.addEventListener("load", Login(), false);
My question is... Will this actually wait for the browser to auto-fill those fields before attempting to login or is the page loading and the browser populating those fields 2 different actions?
I'm creating a GreaseMonkey script that will auto login to a page as long as the user has saved their username and password in the browser. It's pretty simple, it's just checks to make sure that the username field and the password field are not blank and then it clicks the login button automatically.
Every now and then I was running in to an issue to where it didn't login. The page loaded and just sat there. I assumed it was simply due to the page not being fully loaded when the check of the username and password fields were done.
Because of this, I added this to my script.
window.addEventListener("load", Login(), false);
My question is... Will this actually wait for the browser to auto-fill those fields before attempting to login or is the page loading and the browser populating those fields 2 different actions?
Share Improve this question asked Sep 7, 2012 at 17:34 RandomPrecisionRandomPrecision 351 gold badge1 silver badge3 bronze badges 02 Answers
Reset to default 2Did you mean to reference Login
instead of immediately executing it?
window.addEventListener("load", Login, false);
Your way executes Login
before the window loads.
Because there is no standard on how the auto-saved forms work, I would set up a timer on setTimeout()
Er.. I was dumb. Current code does bad things if the person tries to enter their user information.
Untested, quick written code:
function logMeIn() {
var el = document.getElementById("username");
if (el && el.value !== "") {
// Finish the login
} else {
window.setTimeout(logMeIn, 200);
}
}
logMeIn();
Try 2:
// This is a User Script -- runs in its own encloser, won't pollute names back to the main document.
var loginTimer;
function logMeIn() {
var el = document.getElementById("username");
if (el && el.value !== "") {
// Finish the login
} else {
loginTimer = window.setTimeout(logMeIn, 200);
}
}
logMeIn();
// can't use ".onfocus" -- its a userscript.
// Cancel the timer if the username field gets focus -- if the user tries to enter things.
document.getElementById("username").addEventListner("focus") = function(e) {
if (loginTimer) {
window.clearTimeout(loginTimer);
}
}
本文标签:
版权声明:本文标题:javascript - WIll window.addEventListener("load", function(), false); wait for fields to be auto populated by 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744681190a2619417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论