I'm trying to set up a bookmarklet that will go to a web page, enter in some login information, and then automatically click the Login button for me. My problem is that if I simply go to the page and then enter the login information sequentially, the script usually finishes executing before the form elements are loaded. So, I need some way to make the script wait until the page has loaded before entering my login information into the form. I've tried a few approaches so far, and none have worked.
For example:
javascript:window.location = "http://www.msn.com";
window.onload=function(){alert("Page Loaded");};
The alert dialog never shows up. I've also tried using a function that I call periodically using window.setTimeout, but that doesn't work either:
javascript:function doLogin() {
if (document.getElementsByName("login").length > 0) {
document.getElementsByName("login")[0].value = "myUserName";
}
else {
window.setTimeout(doLogin,100);
}
}
window.location="http://my.web.page";
doLogin();
Once again, the login information never gets entered. Does anyone know how I could do this?