How to create a bookmarklet that submits a login form

房东的猫 提交于 2019-12-11 03:39:19

问题


I realize this isn't terrific from a security perspective but humor me.

Is there a way to create a bookmarklet that submits a form, such as a login form. For example, this works, but only if there is a page loaded in the current browser window:

javascript:(function(){document.body.innerHTML += '<form id=f action=https://www.mysite.com/login method=post><input type=hidden name=un value=uname><input type=hidden name=pw value=pword>';document.getElementById("f").submit();})();

Is there some way to construct the form right in the JavaScript and submit that?


回答1:


If you don't need the current page at all, you can completely replace it by having the bookmarklet expression return a string containing the complete new page:

javascript:'<body onload="document.forms[0].submit()"><form method="post" action="https://www.mysite.com/login"><input type="hidden" name="un" value="uname"><input type="hidden" name="pw" value="pword"></form>'

then you don't have to worry about whether the previous page had a <body> or another element with id="f".

(And +1 Matti: innerHTML+= is always a mistake.)



来源:https://stackoverflow.com/questions/3790832/how-to-create-a-bookmarklet-that-submits-a-login-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!