views:

26

answers:

2

How can I append #somehash to all links on a page without depending on a JS framework?

Or is it possible to catch when someone clicks on a link and attach #somehash?

+1  A: 

Make the server add hashed?

Otherwise you will need JS. PS, how do you plan to do anything useful with the hashes without JS enabled?

psychotik
Everything is JS based, I just didn't want to use a framework.
MB
+2  A: 

As pointed out, you're probably doing this the wrong way, but...

var links = document.getElementsByTagName('a');

for(var i = 0; i < links.length; i++) {
    var link = links[i];
    if (link.href.indexOf('#') < 0) {
        link.href += '#somehash';
    }
}
roryf
This looks pretty cool. I don't have server access, since it's an iframe and I am trying to send the parent url for postmessage.
MB