var anchors = document.getElementsByTagName("a"); for (var i = 0; i < anchors.length; i++) { anchors[i].href = "http://www.mysite.com/?redirect=" + anchors[i].href }