Rick
Rick

Reputation: 273

Add domain to relative urls

How can I add http://facebook.com to relative URL's contained within #facebook_urls? Eg:

<a href="/test.html">

becomes

<a href="http://facebook.com/test.html">

#facebook_urls also contains absolute urls, so I want to make sure I don't touch those.

Upvotes: 0

Views: 912

Answers (1)

Alexander Malfait
Alexander Malfait

Reputation: 2701

Something like this?

$('#facebook_urls a').each(function() {
  if(!this.href.match('^http')) {
    this.href = "http://facebook.com/" + this.href
  }
})

Upvotes: 2

Related Questions