0

I'm trying to auto-submit (login) form (datas are remebered by browser) via JavaScript on one specific webpage. I managed to submit test form that I made on my PC very easy using this:

document.forms["formID"].submit();

But when I try that on page it fails. I run JavaScript on page by Greasemonkey and it works fine, run alerts etc. but submit isn't working. Webpage is: http://plusklub.hteronet.ba/Login

I tried to w8 for load with this part of code

document.addEventListener("DOMContentLoaded", function(event) {             
    document.forms["aspnetForm"].submit();
});

Also was using this code from top comment on this question Auto-Submit Form using JavaScript Fail means nothing happens.

A few things I tried:

console.log("test1");
    document.addEventListener("DOMContentLoaded", function(event) { 
        console.log("test2");           
    });
    console.log("test3");
    window.onload = function () { 
        console.log("test4");       
        }
    }
    console.log("test5");
    var fo=document.getElementById("aspnetForm");
    console.log(fo);
    var bu=document.getElementsByClassName("button");
    console.log(bu);
    bu.click();
    setTimeout(function(){ console.log("test6"); }, 3000);

Output folowing:

test1helloworld.user.js:13:3
test3helloworld.user.js:17:3
test5helloworld.user.js:22:3
<form name="aspnetForm" method="post" action="/Login?ReturnUrl=http://plusklub.hteronet.ba/" id="aspnetForm">helloworld.user.js:24:3
HTMLCollection [ <input#ctl04_ctl02_btnSubmit.button> ]
Community
  • 1
  • 1

1 Answers1

0

Unfortunately I dont't have enough rate to add a comment, so I'm going to try my shot.

Usually you need wait the page load before trigger an event like that, which supposedly window.load or onload event property in <body> element should work.

I would recommend create a function to be called through onload event where you can try retrieve the user details (login and pwd), if works, then can add your .submit() call under try...catch exception treatment to check if the browser is raising an error for further debugging. Once done, this may help you to figure out what is going on your code to not be working as expected.

Sorry, to not be so precise in the answer to help you on that, but I hope shed a light on your problem.

Fabricio
  • 76
  • 3
  • Thx for help. Only to inform you guy. Somehow i managed to submit form. Next problem is infinite loop of submiting.Since on each submit same JS code is triggered. I think i'm standing in front of wall, and this is cant be done. :) –  Oct 07 '16 at 23:24
  • 1
    You can handle through cookie or querystring by using a property name like "autologon" with boolean value, if true, your js can skip that. I hope this helps. – Fabricio Oct 07 '16 at 23:28
  • i cant control anything on page i want to login. so i think i cant do anything with query string!? –  Oct 07 '16 at 23:38