How form inline submission works on Facebook requests page
I am writing a bookmarklet to make my life easier in managing bunch of Facebook requests I get everyday from my spammy friends. I know I can just block the app or something, but that is not what I want. I want to manage them, i.e. having 'accept all' or 'ignore all' button.
In order to do that, I have to understand how Facebook take click action from user on the 'Accept' button and the 'x' / ignore button. This is the form I get using Firebug.
<form onsubmit="return Event.__inlineSubmit(this,event)"
style="grouped"
data-gt="<some json data>"
method="post"
action="/ajax/reqs.php"
rel="async">
...
<input type="submit"
id="<some id>"
data-gt="<so开发者_JAVA百科me json data>"
name="actions[<some data>]"
value="Accept">
<input type="submit"
id="u942605_47"
name="actions[reject]"
value="">
...
</form>
What I don't understand is that Event.__inlineSubmit()
will return null. I use jsbeautifier.org to unminimize their js files and load the unpacked version, so it overwrites the minimized version which makes me easier to debug using Firebug.
I don't understand how they submit the form without refreshing the page if it is not the doing of Event.__inlineSubmit();
look at the function definition below. It does not do anything.
I even try to remove the onsubmit property from the form and click the ignore button and it still makes the POST request. I don't think they use AJAX, but I might be wrong.
This is the Event.__inlineSubmit()
definition. Variable a
and document.documentElement.attachEvent
are null. Debug it yourself if you don't mind.
Event.__inlineSubmit = function (b, event) {
var a = Event.__getHandler && Event.__getHandler(b, 'submit');
return a ? null : Event.__bubbleSubmit(b, event);
};
Event.__bubbleSubmit = function (a, event) {
if (document.documentElement.attachEvent) {
var b;
while (b !== false && (a = a.parentNode)) {
b = a.onsubmit ? a.onsubmit(event) : Event.__fire && Event.__fire(a, 'submit', event);
}
return b;
}
};
This is the Event.getHandler()
definition
__getHandler: function (g, h) {
return DataStore.get(g, Event.DATASTORE_KEY + h);
}
Any Javascript guru that is interested in peeling this mystery and explain how they do it?
精彩评论