Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a fragment to the URL without causing a redirect?

Is there is a way how to add hash # to my URL without redirect?

like image 929
Dee Avatar asked Nov 26 '10 02:11

Dee


People also ask

How do I add a hash to a URL?

The hash of a url can be found by creating a new URL Javascript object from the URL string, and then using its hash property to get the value of the hash fragment. Note that this will include the # character also. If the url does not contains a hash, then an empty string "" will be returned.

What are URL fragments?

A fragment is an internal page reference, sometimes called a named anchor. It usually appears at the end of a URL and begins with a hash (#) character followed by an identifier. It refers to a section within a web page. In HTML documents, the browser looks for an anchor tag with a name attribute matching the fragment.

Does URL fragment get sent to server?

Fragment identifiers are not sent to the server. The hash fragment is used by the browser to link to elements within the same page.

What does Window location hash do?

The hash property of the Location interface returns a string containing a '#' followed by the fragment identifier of the URL — the ID on the page that the URL is trying to target. The fragment is not percent-decoded. If the URL does not have a fragment identifier, this property contains an empty string, "" .


1 Answers

window.location.hash = 'something'; 

That is just plain JavaScript.

Your comment...

Hi, what I really need is to add only the hash... something like this: window.location.hash = '#'; but in this way nothing is added.

Try this...

window.location = '#'; 

Also, don't forget about the window.location.replace() method.

like image 196
alex Avatar answered Sep 28 '22 02:09

alex