0

Sorry if this is a duplicate, I know that there are many answers to this but somehow I cannot get any code to work.

I frequently visit a site that has href links on the page like this:

http://www.brilla.com/forum/viewtopic.php?f=25&t=19482&p=719192

but I want to change all links to change to the IP address like this:

http://56.195.106.162/forum/viewtopic.php?f=25&t=19482&p=719192

I have tried using a Jquery in a bookmarklet (http://benalman.com/code/test/jquery-run-code-bookmarklet/) but nothing seems to work.

Many thanks in advance

2 Answers2

0

I am not sure this might work but just try it.

You can set a value of any html attribute by using the .attr() function.

So you might write:

$('.linkClass').attr('src', 'the new value of the src');

Hope it helps.

HTTP
  • 1,674
  • 3
  • 17
  • 22
  • Tried `$('.linkClass').attr('www.brilla.com', '56.195.106.162');` but id does nothing (I'm using Chrome) –  Jul 19 '13 at 01:08
  • @james young No that is not the correct query, do not replace the `.attr('src')` to anything just the `the new value of the src` to your value. – HTTP Jul 19 '13 at 01:21
  • You can verify the new assigned src by doing an alert like: `alert($('.linkClass').attr('src', '56.195.106.162'));` – HTTP Jul 19 '13 at 01:22
  • Thanks, upon closer inspection I think I must change the src since the href links take the src from the site automatically -- Unfortunately `$('.linkClass').attr('src', '56.195.106.162');` still does not work –  Jul 19 '13 at 01:34
  • change `src` to `href` – HTTP Jul 19 '13 at 01:57
  • [How to change the href for a hyperlink using jQuery](http://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery) refer to this link – HTTP Jul 19 '13 at 02:25
0

Thanks for all the answers.

This answer does exactly what I need How do I redirect to a URL using a Google Chrome Extension & Content Script?

Community
  • 1
  • 1