[luci] how to call onload function at template htm file?

Jo-Philipp Wich xm at subsignal.org
Sat Nov 1 11:18:05 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

> In html, I can use <body onload=”somefunction();”>to call 
> somefunction(), when I want do something before load, how to do
> this at luci htm file?

You could either use an inline <script> tag to immediately execute
JavaScript or you simply attach an event listener:

<script type="text/javscript">
  window.addEventListener('load', function() {
    /* do something onload */
  }, false);
</script>

> XHR.poll,looks like autorefesh, but I want to do it only once, can
> I use XHR.poll?

No, in this case use XHR.get:

<script type="text/javscript">
  XHR.get('/some/url', { random: 'post', data: 'foo' },
          function(x, data) {
            /* do something with x.responseText or data if the reply is
             * valid JSON */
          }
  );
</script>


HTH,
Jow
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlRUs1kACgkQdputYINPTPM0ewCcDNh0DgDGMMohyT+KTlBKels5
+EkAoISf6ht80dJ98FD+MZS+pJb11UZ0
=i0F2
-----END PGP SIGNATURE-----


More information about the luci mailing list