views:

226

answers:

1

I'm trying to set up a redirector so that when my AJAX functions change the hash part of the URI, the link is still directly accessible should it be copied and pasted. My current function is below; however, it always returns false!

    //If a hash is found, redirect it
    var current_uri = String(window.location);

    if (current_uri.search('/\#/') != -1) {
            var current_uri_array = current_uri.split('#');
            window.location = current_uri[1];
    }

How can I change the code to make this work? Is there a better way of doing this? Thanks for your help.

Code updated to:

if (window.location.hash) {
    window.location = window.location.hash.substring(1);

}

Which worked.

+4  A: 

Try using window.location.hash directly ;)

Thomas Wanner
I updated the code to://If a hash is found, redirect itif (window.location.hash) { window.location = window.location.hash.substring(1);}And this worked. Thank you.
ensnare