Clinton J
Clinton J

Reputation: 2123

maintaining anchor in http redirect

So right now I have a lot of links on a website pointing to an old HTML file. Most of these links are tied to sectional hash anchors down the page. Currently that HTML page redirects to a new version of the page, which is a PHP file containing the same anchors. I am using a basic javascript redirect script in the . Is there a way that I can get the anchor (if the referring link contained one) and append that to the redirect?

Thank you all in advance.

Upvotes: 2

Views: 1296

Answers (1)

user1694691
user1694691

Reputation:

You can get the hash part of the URL using

window.location.hash

Please note that the value returned includes the hash symbol. So when you append it to the URL, you do not have to append a hashtag as well.

so:

var newURL = 'http://newURL'+window.location.hash;

Hope this helps.

Upvotes: 4

Related Questions