Using Javascript to open a new page and fill out the form values ​​there

I use JavaScript in the bookmarket to fill out 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

It works. However, what I would like to create is a bookmarklet, so that it opens the landing page and fills in the values ​​there; however, it looks like the page is loaded, other JavaScript codes are not executing. So the following does not 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 also experimented with setTimeout to delay the execution of my code, but this did not 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 as soon as I find out that the landing page is fully loaded?

+3
source share
2 answers

Greasemonkey Chrome, , . JS , .

+1

GreaseMonkey , , . - , Greasemonkey, Roboform ..

, : script, . , , , .

. , - .

, , ( ):

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();
     } 
    }

, signon.aspx. , , .

, , , , . !

+7

Source: https://habr.com/ru/post/1764878/


All Articles