在 chrome javascript 控制台中触发表单提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12652788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trigger form submission in chrome javascript console
提问by zemirco
Just a little thing I've always wondered:
只是我一直想知道的一件小事:
Is it possible to submit a form on any webpage, rather than clicking the forms submit button, I want to do it from the chrome console (ctrl+shift+j in chrome)?
是否可以在任何网页上提交表单,而不是单击表单提交按钮,我想从 chrome 控制台(在 chrome 中为 ctrl+shift+j)进行提交?
I've tried a couple ways but I either get an error like
我尝试了几种方法,但我要么得到一个错误
Cannot use function submit on undefined
无法在未定义的情况下使用函数提交
or
或者
HTML tag has not function submit.
HTML 标签没有提交功能。
Any help?
有什么帮助吗?
PS - If you go here and try and submit the form on your right through the console click here
PS - 如果您去这里并尝试通过控制台提交右侧的表格,请单击此处
回答by zemirco
回答by Harry
For your example when working with an iframe:
对于您使用 iframe 时的示例:
// from http://stackoverflow.com/questions/1452871/how-can-i-access-iframe-elements-with-javascript
function iframeRef( frameRef ) {
return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument
}
var inside = iframeRef( document.getElementsByTagName('iframe')[0] );
// from @DeanGrobier
form = inside.getElementById("frm1")
form.submit()
回答by sajawikio
It is inside an iframe in your example. In your case, you must enter this in the console for it to work:
在您的示例中,它位于 iframe 内。在您的情况下,您必须在控制台中输入它才能工作:
var q = window.document.getElementsByTagName('iframe')[1];
var r = q.contentWindow.document.getElementById("frm1");
r.submit();
or, in just one line:
或者,仅在一行中:
window.document.getElementsByTagName('iframe')[1].contentWindow.document.getElementById("frm1").submit();