There is a button

 <button class="btn js-goto-link" role="button" href="" data-goto="https://site.ru" data-goto-referer="true">Вход</button> 

and js code handler:

 activate(); function activate() { $(document).on("click", ".js-goto-link", gotoLinkHandler); } function gotoLinkHandler(e) { e.preventDefault(); var href = $(this).data('goto'); var referer = localStorage.getItem('referal'); window.location.href = href + (referer ? "?referer=" + referer : ""); } 

you need to remake the button on the link a , so that the href attribute href value of the data-goto attribute, but also the referer parameters are added to the get request, which are pulled in the js code from localStorage .
Tell me how to do it right?
And anyway, is there a difference in the transition from window.location.href to the href link attribute?
PS Can this be done with php ?

    1 answer 1

    The only difference is in whom you transfer the responsibility for the transition to a new page. href - Browser (standard script) window.location.href - Document

    In your code, you can change var href = $ (this) .data ('goto'); on var href = $ (this) .attr ('href');

    • I thank for the answer, but I would like to clarify. so the jquery method .data() not much different from .attr() . Why then do these extra manipulations? those. why choose from data-goto or from href using .attr (href). With this kind of coped well and the old version? - word
    • @word yes, that's right. Previously, the data method used attr, and when a dataset appeared at the house of objects, the data method started working with it - lazyproger