开发者

edit all hrefs in the page with jquery

开发者 https://www.devze.com 2023-04-12 07:32 出处:网络
there are hyperlinks in my page link this <a href=\"home.php?id=2\">some text</a> <a href=\"http://myDomanin.com/home.php?id=3\">some text</a>

there are hyperlinks in my page link this

<a href="home.php?id=2">some text</a>
<a href="http://myDomanin.com/home.php?id=3">some text</a>
<a href="http://myDomanin.com/home.php?id=4">some text开发者_开发技巧</a>
<a href="home.php?id=5">some text</a>

I want to write a javascript to change hrefs to this new link:

if OldHref = http://myDomanin.com/home.php?id=3 then

NewHref = http://myNewDomain.com/{base64Encode of OldHref}

found a plugin to make base64 encode here


$('a').each(function(){
  this.href = 'http://myNewDomain.com/' + Base64Encode(this.href);
});

Or something of the sort...


Non, jQuery method:

var anchors = document.getElementsByTagName('a');
for (var a = 0; a < anchors.length; a++){
  anchors[a].href = 'http://myNewDomain.com/' + Base64Encode(anchors[a].href);
}
0

精彩评论

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

关注公众号