0

I made quite popular UserJS for Facebook, but since FF 3.6.13 version it doesn't work (for that version). I just have no idea how can I click such elements:

<input value="Accept" type="submit" name="something... asdf" />

? Clicking such buttons with mouse redirects to another page.

What my script does is searching for such elements with Xpath and then clicking them with simple acceptbutton.click();

It works great on Opera, Chrome and FF <3.6.13 , but in newest version nothing happens. I tried also both fireEvent and eventFire functions which I've found here on stackoverflow and which help me often, but this time they can't.

Probably using JQuery's click() function would help ,but I cannot use jquery in my userjs.

I tried also acceptbutton.form.submit(); but it redirects me to wrong page.

Edit :

Ok i am adding code fragment

                 var acceptbuttons = xpath(document,'//label[@class="uiButton uiButtonConfirm"]/input');
        for (var i = 0; i < acceptbuttons.snapshotLength; i++) { 
        //will search for particular accept button
            var acceptbutton = acceptbuttons.snapshotItem(i);
            var acceptbuttonName = acceptbutton.getAttribute("name");

            if(acceptbuttonName.indexOf(urlPart)!=-1)
            {
            // it founds button but function below do nothing in FF
            acceptbutton.click();return;
            }
        }

Thanks for any help!

Kostrzak
  • 161
  • 4
  • 19

3 Answers3

1

You can use the click() method of the submit button in the latest Firefox. You have something else wrong. Do you have an onsubmit event on the form that is preventing the click from working, or do you have the wrong button?

I submitted this by pasting javascript: document.getElementById('submit-button').click(); void(0); in my location bar in Firefox 3.6.13. Credit for that idea goes here: JavaScript auto-POST with NAME

Community
  • 1
  • 1
Hemlock
  • 6,130
  • 1
  • 27
  • 37
0

Hmm, wont do a simple document.whatever_formname.submit(); do the trick?

Bosh
  • 1,237
  • 1
  • 16
  • 23
  • As i said, I tried it, but it redirects me to different page than normal click. – Kostrzak Dec 28 '10 at 21:12
  • 1
    acceptbutton.form.submit() looks strange to me... Does your form has the name "form"??? The correct syntax is document.formname.submit() as far as i remember... – Bosh Dec 28 '10 at 21:21
  • I took it from this StackOverflow question : http://stackoverflow.com/questions/991367/how-to-get-the-form-parent-of-an-input . That page hase over 50 forms , none of them has name so i can call it just like that, but I doubt submiting form is what i am searching for. I just need to simulate click on that button. – Kostrzak Dec 28 '10 at 21:31
0

If acceptbutton.form.submit(); doesn't work because the value="Accept" part is not sent, why not add a hidden input so that it will be?

var hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.name = acceptbutton.name;
hiddenInput.value = acceptbutton.value;
acceptbutton.form.appendChild(hiddenInput);
acceptbutton.form.submit();
PleaseStand
  • 31,641
  • 6
  • 68
  • 95
  • It does same as Booosh's code. Maybe it submits value but it's not what i want, cause it redirects me to wrong page. With normal mouse click or acceptbutton.click() in other browsers it redirects me to new page where I can fire other script functions. – Kostrzak Dec 28 '10 at 21:27