On Feb 27, 2:05 pm, Mike Soh <[email protected]> wrote:
> I've noticed a really weird behavior of GM_xmlhttpRequest.  It seems
> like the process is async, instead of sync.

That's correct. It is async. The "onload" callback will run when the
data is returned from the internet. In your case it will be called
once for each link.

The problem is you don't have closure. I believe the following will
solve that (untested)

function getLink(i) {
     GM_log('inspecting item: ' + i);
     var p = links[i];
     GM_log('href: ' + p.getAttribute('href'));
     GM_xmlhttpRequest({
          ... (shortened for brevity. no change here)
     });
}

for (var i = 0; i < links.length; i++) {
     getLink(i);
}

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to