11

I'm trying to call an HTML page like this with the Raspbian's default web browser and it leads me just to the default login-page.

Neither does it with Midori on the desktop.

When calling the exact same page with Firefox or Google Chrome on the desktop it just works.

In the first place, I had:

<body onLoad="doLogin()">

Which had the exact same behavior, but worked on Firefox and Chrome. Is there any way on getting this done with the built-in browser on raspbian?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
<!--
function doLogin() {
document.form1.action="https://ip/sub/main.html?page=map_info&id=177";
document.form1.submit();
}
//-->
</script>
</head>
<body >
<form name="form1" id=form1 method="post">
    <input type="hidden" name="process" value="login">
    <input type="hidden" name="page" value="start">
    <input type="text" name="user" value="User">
    <input type="password" name="password" value="Pass">
</form>
<script>window.onload=doLogin;</script>

</body>
</html>

PS. User, Pass, and the URL are changed to not expose internal data.

alsternerd
  • 316
  • 2
  • 12
  • 3
    If you add "alert('hi');" in to your doLogin function does the alert appear? That will show if the JavaScript is running – rob Dec 04 '15 at 11:39
  • 1
    It does appear, unfortunately I did not find a solution until today. The Only thing not tranferred today is giving the user and password to the page. It won't login. At least the redirect works.

    The Function is called with both tries and works, but not the transfer of the userdata.

    – alsternerd Jan 07 '16 at 10:29
  • 1
    Maybe it's because you have your JavaScript code inside of the script tags wrapped in an Html comment – Mohammad Ali Jun 14 '16 at 17:17
  • 1
    That's to keep everything in one file, since two files seem too bloated for that case. I wasn't able to get the post/get-data correctly, so that's what I'd come up with.

    For now, I'm using vnc to login to the site, everytime the machine boots up.

    – alsternerd Jun 16 '16 at 13:48
  • 3
    check if the ID is with Quotation marks. ID="form1". could this work? in js change the submit to document.getElementById('form1').submit(); – Joe Platano Jul 08 '16 at 03:58
  • have you considered adding a delay to the "doLogin" function? – Mohammad Ali Dec 07 '16 at 04:36
  • 1
    there are some brackets missing: add on the end of window.onload =doLoginnormal brackets window.onload=doLogin() – Joe Platano Dec 15 '16 at 05:05
  • although somewhat archaic using HTML comments to wrap JS code is legal, and should not prevent execution of the code. script should have a type attribute though. – Jasen Mar 24 '18 at 06:53
  • 1
    The problem may lie in the field types. Try changing type="text" and type="password" to type="hidden". My thought here is that the former two may need to be displayed and populated before their value can be used. And this could easily be browser dependent. – David G. Jan 29 '23 at 13:34

1 Answers1

1

Since I cannot comment I'll post my answer here. The problem is with your <script>window.onload=doLogin();</script>. As documented you should always add event listeners differently than you have done. In order to add a window.onload listener do the following:

<script>
window.addEventListener('load', (e) => {
   console.log('window loaded...');
   doLogin();
});
</script>

In addition to the aforementioned way of adding event listeners, as mentioned in one of the comments you should retrieve the form itself in JS by utilizing the getElementById method. Like this:

<script>
  function doLogin(){
    var frm = document.getElementById('form1');
    frm.action = "......";
    frm.submit();
  }
</script>
MatsK
  • 2,791
  • 3
  • 16
  • 20
sativay
  • 51
  • 2