How can I represent a hash key in a URL parameter?

I have a Spring-MVC application with Freemarker as a view component.

My templates create several links that point to my application and which include URL parameters containing a hash key ( #).

Example:

: Q#106368 11

URL created by Freemarker with encoded parameter: testurl.html?key=Q%23106368%2011

I use JavaScript to redirect to this URL (reason: I use JS to control 2 frames at the same time).

The redirect method is simple:

    function redir(url) {
        window.location.href = url;
    }

JS call created by Freemarker looks like

<a href="javascript:redir('http://localhost:8080/testappp/testurl.html?key=Q%23106368%2011');">test</a>

My problem is that the browser / Javascript converts the URL into an encoded parameter, considers that there is #and is disabled there.

window.location.href='http://...', . URL-, , URL- #.

?

, #, . $$$hash$$$, . , ...

+5
3

, URL. encodeURI(). #. # %23.

JS :

    function redir(url) {
        url = encodeURI(url);
        url = url.replace(/#/g, '%23');
        window.location.href = url;
    }

escape(), encodeURI() encodeURIComponent()

+7

? FireFox 5, %23 # . , ? , , , ?

, , :

<a onclick="url = 'http://localhost:8080/testappp/testurl.html?key=Q%23106368%2011';" href="javascript:redir(url);">test</a>

, href . , # %23.

+2

encodeURIComponent/decodeURIComponent , encodeURI, / '#' event '/'

0

All Articles