简体   繁体   中英

How can I detect a login form in a webpage using JavaScript?

I want to use JavaScript to detect if a webpage has a login form or not in order to autofill the user's credential. I'm thinking of checking if there is an input with id="username"/"id", however each website will have its own naming convention. What is the proper way to implement this?

I think the best way is to search for an input of type password. They are used only almost solely for logins. But you will also need to distinguish between login and signup forms. One way of doing it is counting the number of password inputs. Most signups have 2 password inputs to confirm. But this is less sure. You will probably need more filters. Maybe also try to find the words "signup" or "login" enclosed in the form tag, or immediately preceding it.

There is no one sure way. You'll have to use your ingenuity.

I also had to undergo the same scenario. I used following criteria to detect whether login panel exists or not.

By checking whether type="submit" ( if login panel exists, in most cases form should be there to submit the data ) and type="password" ( password need to exists in order to capture the password typing in hidden manner ).

But still there is no proper way. You need to come up with your filters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM