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
From stackoverflow
-
Event handlers?
<body onload="somefunction"> <img src="blah.jpg" onLoad="somejavascriptfunction()" onclick="someotherfunction">and so on.Can be done with most elements.
-
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);Crescent Fresh : You don't need jQuery to re-use a function like this.acrosman : 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. -
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.
Crescent Fresh : `.each` is redundant here. You can just use `$("link, script, style, a, img").load`. Just a tip.apast : Yes!! We need that solution. That's the type of request that I qant handle! Thanks, And Pastapast : 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
0 comments:
Post a Comment