Bookmarklet: Submit a login form using javascript within a bookmark

If you’re like me, you have many bookmarks to administration areas that require authentication. For you, this script is a priceless time-saver.

Let’s say your login page has a form similar to the following…

<form action="/login.php" method="post">
    <label>Username: <input type="text" name="user"></label>
    <label>Password: <input type="password" name="pass"></label>
    <input type="submit" value="Log In">
</form>

Some logins simply cannot be stored in the browser’s password system. So, to save you the extra effort of manually logging in on each visit to such pages, create a bookmark that automatically logs you into the system.

Here’s the code to submit that form using a bookmarklet…

Red text indicates what should be changed…

javascript:'<html><body onload="document.forms[0].submit()"><form method="post" action="http://yourdomain.com/login.php"><input type="hidden" name="user" value="yourusername"><input type="hidden" name="pass" value="yourpassword"></form></body></html>'

As long as you have a basic understanding of HTML forms and JavaScript, you should be able to modify the above code to suit your specific needs 🙂

Warning: Since your username and password are stored in plain-text within the bookmark, you should never implement this script on a computer or device accessible by other users.

One thought on “Bookmarklet: Submit a login form using javascript within a bookmark”

Leave a Reply

Your email address will not be published. Required fields are marked *