I don't use GreaseMonkey as a personal rule, to code for browsers that shouldn't use it. Bookmarklets are a least-common-denominator approach to automate logins when your system is locked down and won't allow install of Greasemonkey, Roboform, etc.
I've coded a lot of login bookmarklets and thought about what you're trying to do: add some script that gets executed after a page loads. I came to this page looking for the solution, but now I'm glad it doesn't work.
Think about the security implications of this. If it were possible to echo keystrokes to to a loaded page, it would also be able to listen to keystrokes and send them elsewhere -- very bad.
If you want to automate logins, try a bookmarklet pattern like this (remove line breaks):
javascript:
u='my_username';
p='my_password';
l='https://my_server/signon.aspx';
if(location!=l)location=l;
else{
g=document.getElementById;
ue=(g('username') || g('userid') || g('login_name'));
if(ue){
ue.value=u;
pe=(g('password') || g('pw') || g('pin'));
pe.value = p;
b=(g('submit_button') || g('signon_button') || g('login_button'));
document.close();
if(b)b.click();
}
}
Clicking the link once takes you to the signon.aspx page. Once the username field is available on the loaded page, clicking the same link again will fill the form and submit.
So it's one more click than you hoped, but if you put the bookmarklet on a toolbar it's hardly any delay. Good luck!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…