单击Greasemonkey中的按钮后如何等待页面加载?

时间:2013-03-08 20:41:48

标签: javascript jquery ajax greasemonkey tampermonkey

执行下面的脚本时,单击按钮后,其余代码不会执行。

checkTypeOfRegistration()

function checkTypeOfRegistration() {
    waitForKeyElements("div.registrationName", becomeFreeMemberReg);
}

function becomeFreeMemberReg() {
    var randomnumber = Math.floor(Math.random() * 1001) // random number between 0 - 1000
    var testEmail = first2OfEmail + randomnumber + atEmail // email will be: firstlast + random number @email.com
    document.getElementById('RegistrationEx1_FirstName').value = randomFirstName();
    document.getElementById('RegistrationEx1_LastName').value = randomLastName();
    document.getElementById('RegistrationEx1_Email').value = testEmail;
    document.getElementById('Password').value = "test";
    document.getElementById('RegistrationEx1_ZipCode').value = "91740";
    document.getElementById('txtInternationalPhone').value = "6267121111";
    document.getElementById('RegistrationEx1_PrimaryRole').value = '220';
    // This clicks the registration button on the form
    waitForKeyElements("a.button.large.blue:contains('Register Now')", registerNow);

    // >>>>> <<<<<
    // THE WAIT FOR KEY ELEMENT BELOW IS NOT GETTING EXECUTED WHEN THE PAGE LOADS
    waitForKeyElements("th.productShadeA", test);

    function registerNow(jNode) {
        //document.getElementById("div.registration.Action").submit()
        var clickEvent = document.createEvent('MouseEvents');
        clickEvent.initEvent('click', true, true);
        jNode[0].dispatchEvent(clickEvent);
    }

    function test() {
        alert("tess")
    }
}

当脚本到达这些行时,在加载以下页面时,test函数未执行:

// This clicks the registration button on the form
waitForKeyElements("a.button.large.blue:contains('Register Now')", registerNow);

// >>>>> <<<<<
// THE WAIT FOR KEY ELEMENT BELOW IS NOT GETTING EXECUTED WHEN THE PAGE LOADS
waitForKeyElements("th.productShadeA", test);

0 个答案:

没有答案