简体   繁体   English

如何填写表格并按页面加载提交

[英]How to complete a form and press submit on page load

I want to write a simple Greasemonkey script, to complete and submit this form every time the page loads. 我想编写一个简单的Greasemonkey脚本,以在每次页面加载时完成并提交此表单。

Enter a predefined email address (email@gmail.com) into the script, then submit it each time 在脚本中输入预定义的电子邮件地址(email@gmail.com),然后每次提交

<div class="col-md-4">
    <label for="Content_C001_LI_02_txtEmail">Send proof of delivery email to:</label>
</div>
<div class="col-md-5">
    <input name="ctl00$Content$C001$LI_02_txtEmail" type="text" value="email@gmail.com" id="Content_C001_LI_02_txtEmail" class="form-control" onkeypress="return clickButton(event,'Content_C001_LI_02_btnSend')"><span id="Content_C001_ctl23" style="display:none;"></span>
</div>
<div class="col-md-3">
    <button onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate('LI_02'); __doPostBack('ctl00$Content$C001$LI_02_btnSend','')" id="Content_C001_LI_02_btnSend" type="button" class="btn btn-primary btn-inline-label" validationgroup="LI_02">Send</button>
</div>

Once the form has been submitted, this piece of code changes. 提交表单后,这部分代码将更改。

So I will need to figure out how to only run the script if it hasn't already been submitted before. 因此,我将需要弄清楚如何仅在之前尚未提交脚本的情况下运行该脚本。

<div id="Content_C001_ctl00" class="alert alert-success" style="display:none;">

to

<div id="Content_C001_ctl00" class="alert alert-success">
Proof of delivery has been successfully emailed to email@gmail.com <br>

Your help is much appreciated! 非常感谢您的帮助! :) :)

Something like this maybe? 像这样的东西?

document.addEventListener ("DOMContentLoaded", checkSubmitEmail);

function checkSubmitEmail(){
    var myEmail = 'vns@gmail.com';

    // 1- check if email has been submitted
        var submitted = document.getElementById('Content_C001_ctl00').innerHTML.startsWith('\nProof of delivery has been successfully emailed to ' + myEmail);

    // 2- if not continue
        if (!submitted){
            // 3- fill in email
                document.getElementById('Content_C001_LI_02_txtEmail').value='' + myEmail;

            // 4- click button
                document.getElementById('Content_C001_LI_02_btnSend').click();
        }

}

It's hard to tell precisely, but a cookie may be what you are looking for here. 很难准确说出,但是cookie可能就是您在这里寻找的东西。

MDN's documentation on the JS Cookie interface JS Cookie界面上的MDN文档

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

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