M
M
MaksKein2012-10-10 16:15:20
PHP
MaksKein, 2012-10-10 16:15:20

How to remove anchor (#, hash, hash, hash) in URL?

The situation is as follows:
there is a website on a certain CMS, it has an order form page at /zakaz/, after clicking on the “Submit” button, the user is redirected to the /zakaz/ok/ page by means of CMS. Once on the form itself there was an html anchor #form (so that the page at /zakaz/#form would be displayed starting from the first line of the form). Later, it became clear that if a user fills out a form from the /zakaz/#form URL in the browser, the form does not work correctly (there is no redirect).

The task is to change the URL in the user's browser to /zakaz/ when a user enters /zakaz/#form.

Is it possible to do this? Do I understand correctly that since only /zakaz/ is requested to the server, and #form is already processed on the client, neither php nor mod_rewrite via .htaccess will help, i.e. only with javascript?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Vyacheslav Belyaev, 2016-02-03
@TroL929

The question is of course outdated, well, while the answer is at hand, I will answer. Maybe someone will come in handy.

history.pushState('', document.title, window.location.pathname);

I
Ilya Shabanov, 2012-10-10
@ishaba

window.location.href.split('#')[0]
something like this, but it's better to add / to the form action

S
Sims, 2012-10-10
@Sims

As already mentioned, the hash can be removed with the help of javascript by changing the window.location.hash property. The server will not be able to remove the hash, because it is not included in the request parameters by the browser and, accordingly, is not sent to the server (in general, the only way to send the hash to the server is to manually add it via javascript as one of the parameters before sending the request). Moreover, even if the server knows that the hash is present in the request, in general it will still not be able to remove the hash from the request parameter (via a redirect response), since according to the w3c specification, the browser is required to automatically add a hash (fragment identifier) ​​to the query string after processing the redirect (http://www.w3.org/TR/cuap#uri).

A
Alio, 2015-05-04
@Almazka987

jquery code - setting the transition to the anchor so that the hash is not displayed in the address bar after the transition:

$('a[href*=#]').bind("click", function(e){
      var anchor = $(this);
      $('html, body').stop().animate({
         scrollTop: $(anchor.attr('href')).offset().top-100
      }, 1000);
      e.preventDefault();
   });

I
Ilya Shabanov, 2012-10-10
@ishaba

I read it several times but still don't understand...
Your form is not sent if you go to domainname.ru/zakaz/#form ?
And at the same time, she recovers by domainname.ru/zakaz/ ?

D
deilux, 2012-10-10
@deilux

In general, the property is responsible for the anchor in the address window.location.hash. Just need to clean it up

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question