Greasemonkey error when attempting click() event

0

I'm trying to click a button on a page and I can get the length of the object no problem but when I try to click the item I get this error:

Error: uncaught exception: [Exception... 
 "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  
 location: "JS frame :: resource://greasemonkey/runScript.js :: <TOP_LEVEL> :: line 3"  data: no]

Here is the code I'm using:

(function(){
    $('body').append('<input type="button" id="autobop" value="autobop" />');   
    $('#autobop').click(function(){
            //buJmnfJwRG
            alert($('#buJmnfJwRG').length);
            $('#buJmnfJwRG').click(); // error occurs here
            /*
            setInterval(function() {

            }, 2000);*/
        });
})();
jquery
greasemonkey
asked on Stack Overflow Dec 13, 2011 by mcgrailm • edited Dec 13, 2011 by mcgrailm

3 Answers

0
$(document).ready(function(){
    $('body').append('<input type="button" id="autobop" value="autobop" />'); 

        $('#autobop').click(function(){
            //buJmnfJwRG
            alert($('#buJmnfJwRG').length);
            $('#buJmnfJwRG').click();
        });                
});
answered on Stack Overflow Dec 13, 2011 by flux • edited Dec 13, 2011 by Brock Adams
0

Link to the target page. Where did #buJmnfJwRG come from, was it on the target page or added by your script?

Unless #buJmnfJwRG's click, event handler was created by your script, using jQuery, you cannot activate it using $('#buJmnfJwRG').click(); (usually).

Try:

$('#autobop').click ( function () {
    //buJmnfJwRG
    alert ( $('#buJmnfJwRG').length );

    var clickEvent = document.createEvent ('MouseEvents');
    clickEvent.initEvent ('click', true, true);
    $('#buJmnfJwRG')[0].dispatchEvent (clickEvent);
} );
answered on Stack Overflow Dec 13, 2011 by Brock Adams
0

I had a dev take a look....

$(document).ready(function(){

$('body').append('<input type="button" id="autobop" value="autobop" />');

$('#autobop').click(function(){

//buJmnfJwRG

alert($('#buJmnfJwRG').length);

$('#buJmnfJwRG').click();

});

});
answered on Stack Overflow Dec 13, 2011 by rgeaux • edited Dec 14, 2011 by Brock Adams

User contributions licensed under CC BY-SA 3.0