开发者

Add domain to relative urls

开发者 https://www.devze.com 2022-12-26 04:37 出处:网络
How can I add http://facebook.com to relative URL\'s contained within #facebook_urls? Eg: <a href=\"/test.html\">

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 co开发者_JAVA技巧ntains absolute urls, so I want to make sure I don't touch those.


Something like this?

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

精彩评论

暂无评论...
验证码 换一张
取 消