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
3 Answers
Reset to default 2jQuery:
$("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
版权声明:本文标题:How to intercept a site http request using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745229373a2648755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论