Simple script to replace a link
|
|
I need to replace...
with...
I've tried messing with an existing script but can't figure out how to add the .jpg at the end.
|
|
|
link[i].href = '/sample/id'+link[i].href.split('id=')[1]+'.jpg'; |
|
|
Thanks! |
|
|
I just noticed it's changing all the links. Is there a way to only affect links that have page=sample? Thanks |
|
|
|
|
|
ima noob :) Can't get it to work. I've tried all kinds of this but nothing. Here's the old and new...
|
|
|
Use sizzlemctwizzle's version, but put it in your original replace function.
var link;
link = document.body.getElementsByTagName("a")
for (var i = 0; i < link.length; i++) {
link[i].href = link[i].href.replace("index.php?page=sample&id=", "/sample/id"+link[i].href.split('id=')[1]+".jpg");
}
Note: you may have to escape some characters in the replace. |
|
|
Thanks Yansky
Instead of being |
|
|
var lianks = document.evaluate(
|
