Computers, Programming, Technology, Music, Literature

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 , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: