JQuery.address how to remove # from url (javascript window.location remove #)

I need to remove # from url when event.value value is == in /. I have a lighbox with jquery.address that stores links to open images, when I close it, I need to remove the # sign because this window causes it to scroll up.

I successfully deleted the # sign with this: window.location.href.slice (0, -1); but, as you can see in the above code, you can rewrite the url when the page loads, and not just after my event.

How can I link this javascript only when my full action happens as this function is called olny when I close the lightboxes.

Here I add my code with comments. Thank you all

$.address.change(function(event) {
    curLink = event.value;
    if(curLink != '/') {

    // here my stuff, jquery.address generates url with reference 

    // ex: mysite.com/cat/subcat/page.html#one

    } else {  

        $('#element').animate({opacity:"0"},{duration:100, easing:"quartEaseOut", complete: function () {

        // here I need to remove the hash only after the complete 

        // ex: mysite.com/cat/subcat/page.html#  >  mysite.com/cat/subcat/page.html

        window.location.href.slice(0, -1);           
        $(this).hide(); 
    }});   
  }   
});
+3
5

window.location.hash = '' , , URL- (, http://ajaxcssblog.com/jquery/url-read-request-variables).

+2

newHash = window.location.hash.substring(1);

console.log(newHash);

, URL-, , , .

, ,

newHash = window.location.hash.replace('#', '');

console.log(newHash);
+2

, , . , .

function removeDeepLink(event) {
    window.location.hash = 'foo';
};
+1

( URL- )

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

http://www.google.com/#top

http://www.google.com/
+1

window.location.hash = '' .

window.location.href.slice(0, -1);works! the problem that I cannot solve is how I can bind this JavaScript instruction only after the full jQuery event (it now fires when the page loads).

I think this is still a dumb JavaScript call after jQuery

Thank you

0
source

Source: https://habr.com/ru/post/1776848/


All Articles