admin管理员组

文章数量:1415139

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?

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?

Share Improve this question edited May 5, 2016 at 14:20 Andre Pastore asked Sep 21, 2009 at 20:02 Andre PastoreAndre Pastore 2,9074 gold badges35 silver badges44 bronze badges 3
  • 2 Your question isn't vary clear, what type of "operation do you want to execute" and when do you want it to fire, after the objects are loaded into the DOM or when the request is made... It's likely that your trying to do something outside the conventions of proper web development. Maybe ask your self, "why do I need to do this" in the first place, you may find it pletely unnecessary. – JP Silvashy Commented Sep 21, 2009 at 20:21
  • 1 you cant intercept site http by javascript, because javascript file itself is an http request, you need a web server and some sort of server side technology to do that – Ayyash Commented Sep 22, 2009 at 4:20
  • Hi, I need handle HTTP requests because I want to observe and execute some action when some object perform that event. i.e., when img.src load some content from the server, I need to calculate the time spend for it. Firebug and Yslow do that. But, I don't know how. []'s, And Past – Andre Pastore Commented Sep 22, 2009 at 13:11
Add a ment  | 

3 Answers 3

Reset to default 2

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.

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);

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

Can be done with most elements.

本文标签: How to intercept a site http request using javascriptStack Overflow