Computers, Programming, Technology, Music, Literature

Archive for the ‘javascript’ Category

Javascript: Change all hyperlinks in a page

leave a comment »

So, I had to download some youtube videos from the youtube search page, and for the past couple of years I have been fond of savemedia.com (kissyoutube, and site alike). I am not a big fan of youtube downloaders, and add ons; moreover these websites are online and all you need is change the video http://www.youtube.com/watch?v=qJCedFwrVqk to http://www.savemedia.com/watch?v=qJCedFwrVqk. Next you need to accept and run a java plugin and download these videos instantly.

Below javascript allows you to do exactly the same. Get all hyperlinks in the page, replace youtube.com with savetube.com. 

var anchors = document.getElementsByTagName("a");

for (var i = 0; i < anchors.length; i++) {
    anchors[i].href = anchors[i].href.toString().replace("youtube.com", "savemedia.com")
}

image

If you have JQuery enabled on a website, then you may use

$('a').each(function(){
$(this).attr('href', this.href.toString().replace('microsoft.com', 'apple.com'));
});

image

Advertisements

Written by gmaran23

December 5, 2013 at 1:36 am

Posted in javascript

Tagged with , , ,