How would I have a jQuery (preferably) script iterate through every single <a> tag and find any that don’t start with
http://www.example.com/
and change the src attribute to
http://www.example.com/outbound/?verifyAge=0&dest='+encodeURIComponent(original_src)
and also apply rel="external" target="_blank"?
Here‘s a quick proof of concept:
HTML:
JavaScript:
Essentially what the JavaScript is doing is finding any
aelement which doesn’t begin withhttp(you’ll want to expand that conditional logic for your own needs, as well as handle any issues with having to escape the slashes in the URL or anything like that), grabs a reference to it as a jQuery object (I don’t remember ifthisis already a jQuery object, if it is you can omit that part), modifies itshrefattribute and adds atargetattribute.