Load below code at /login/index.php
.
<script src="Moodle2LoginAutoFocusUsername.js"></script>
or
<script>
// Copy and paste the content of `Moodle2LoginAutoFocusUsername.js` here.
</script>
/** | |
* Moodle 2: Login: Auto focus username | |
*/ | |
(function(){ | |
function focus_to_username() { | |
if (!location.href.match('/login/(index\.php)?$')) return; | |
let e = document.getElementById("username"); | |
if (e) e.focus(); | |
} | |
function onDOMContentLoaded(f) { | |
if (document.readyState === 'loading') { | |
document.addEventListener('DOMContentLoaded', f); | |
} else { | |
f(); | |
} | |
} | |
onDOMContentLoaded(focus_to_username); | |
})(); |