如何创建提交登录表单的小书签 [英] How to create a bookmarklet that submits a login form

查看:81
本文介绍了如何创建提交登录表单的小书签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从安全的角度来看,我意识到这并不可怕,但我很幽默.

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();})();

是否有某种方法可以直接在JavaScript中构造表单并将其提交?

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

推荐答案

如果根本不需要当前页面,则可以通过使bookmarklet表达式返回包含完整的新页面的字符串来完全替换当前页面:

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>'

那么您就不必担心上一页是否包含<body>或具有id="f"的另一个元素.

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

(并且+1 Matti:innerHTML+=总是 一个错误.)

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

这篇关于如何创建提交登录表单的小书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆