views:

37

answers:

1

I am using JavaScript in a bookmarklet to populate form elements on a website:

javascript:var f = document.forms[0];
f.getElementsByTagName('input')[0].value = 'myname';
f.getElementsByTagName('input')[1].value = 'mypassword';
f.getElementsByTagName('input')[2].click

This works. However what I would like to create is a bookmarklet so that it opens the target page, and populates the values there; however it seems that onces the page is loaded, other JavaScript codes are not executed. So, the following doesn't work.

javascript:window.location("mywebsite");var f = document.forms[0];
f.getElementsByTagName('input')[0].value = 'myname';
f.getElementsByTagName('input')[1].value = 'mypassword';
f.getElementsByTagName('input')[2].click;

I have also experimented with setTimeout to delay the execution of my code, but that didn't work.

javascript:var f = document.forms[0];setTimeout("f.getElementsByTagName('input')[0].value = 'myname';f.getElementsByTagName('input')[1].value = 'mypassword';f.getElementsByTagName('input')[2].click;",1000);

How can I load my script once I know the target page is fully loaded?

+1  A: 

Greasemonkey is built into Chrome, sounds like you are trying to reinvent the wheel. Install a JS file and it will run when the page loads.

epascarello
Thanks, sometimes the answer actually is obvious.
ustun