Im scraping a website and Im trying to redirect to another website if people click on a link so I injected some javascript:
$('a').on('click', function() {
for (var ls = document.links, numLinks = ls.length, i=0; i<numLinks; i++){
ls[i].href= 'http://mywebsite.com/test.php?url=' + this;
}
});
It works, but it only works on actual links <a href..>
. Sometimes a click on an element will act as a link do to some javascript, I also would like to capture that 'event'. It has me thinking about XMLHttpRequest
if I Im not mistaken the browser has a built in object called XMLHttp
object, which one could use to intercept ajax calls:
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async) {
//do something...
So my question is: Does anything similar exist for listening and altering outgoing URL's?