繁体   English   中英

JavaScript注入

[英]Javascript injection

我想用JavaScript明确填写并提交表单。 首先,我以为我必须使用window.open,但这肯定是错误的,因为如果加载了它,那么我写在html文件中的脚本的左侧将被忽略。

我必须创建一个.js文件并解雇该文件吗?

呃...不完全确定这与注入有何关系...您可以在几行代码中使用jQuery来实现。

说您具有以下形式:

<form id="theForm" name="testForm" action="whatever.php" method="get">
    <input type="text" name="cow" />
    <input type="text" name="sheep" />
    <input type="text" name="pig" />
    <input type="submit" value="Submit" />
</form>

如果您已加载jQuery ,则只需执行以下操作:

function submitForm(){
var cowVal="Cows go moooo!";
var sheepVal="Sheep go baaaaaaah!";
var pigVal="pigs go sooooeeeeeeeh!";
$("#theForm input").eq(0).val(cowVal).next().val(sheepVal).next().val(pigVal).parent().submit();
}

希望有帮助!

我将使用上面兄弟使用的确切代码,并向您展示如何更改值并使用JavaScript提交表单。 码:

<form id="theForm" name="testForm" action="whatever.php" method="get">
    <input type="text" name="cow" />
    <input type="text" name="sheep" />
    <input type="text" name="pig" />
    <input type="submit" value="Submit" />
</form>

js注入看起来像这样:

document.getElementsByName("cow")[0].value="the value you want to submit";
document.getElementsByName("sheep")[0].value="the value you want to submit";
document.getElementsByName("pig")[0].value="the value you want to submit";
document.getElementsByName("Submit")[0].value="the value you want to submit";
document.getElementsByName("Submit")[0].click();

此代码应在表单中输入所需的值,然后同时提交。 如果网站具有检测输入和提交表单的时间间隔的功能,则可以将setTimeout()setInterval()与代码一起使用(自动检测)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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