views:

346

answers:

3

Hi,

I need to hook all links, images, css and js call URLs inside my site and execute some operation when an event occurs with then.

Anybody knows how to handle all these events?

Best regards,

And Past

A: 

Event handlers? <body onload="somefunction"> <img src="blah.jpg" onLoad="somejavascriptfunction()" onclick="someotherfunction"> and so on.

Can be done with most elements.

Jonas B
A: 

If you need to catch everything with the same function you could use jQuery. Something like this would attach a function to all links:

$('a').click(somefunction);
acrosman
You don't need jQuery to re-use a function like this.
Crescent Fresh
No you don't, but the selectors make it easy to make sure you get all the places you'd like to attach your function, while the load and click functions help handle cross browser issues smoothly.
acrosman
+1  A: 

jQuery:

$("link, script, style, a, img").each(function(){
    $(this).load(function(){
        // do stuff when each of these elements is loaded
    });
});

Not entirely sure if that is what you want, as your question isn't terribly clear, but that is how you can bind something to the load event for each of those element types.

inkedmn
`.each` is redundant here. You can just use `$("link, script, style, a, img").load`. Just a tip.
Crescent Fresh
Yes!! We need that solution. That's the type of request that I qant handle!Thanks,And Past
apast
But, I need some more complete artifact to achieve all HTTP requests. i.e., when jquery execute $.get('remoteFile.html',...) . How can I handle that request?[]'s,And Past
apast