0

I'm not able to do it, i need to modify this script (thats works fine) and add a query string remove function at the end. In other words, when i click on a button link (.modal-close) i need to perform all the function (toggleClass, fadeOut...), wait 1 second and then remove query string from url.

the functions are:

 $(function() {
    $(".modal-close").click(function() {
        $("html").toggleClass("lightbox-is-open");
        $("html").toggleClass("lightbox-is-fixed");
        $(".dialog-container, .glasspane").fadeOut(200).addClass("hidden");
return false;
    });
  });

now, i need to remove the query strings, this would be fine?

window.location.href = window.location.href.split('?')[0];

I'm not able to combine all together.. (i'm a very dummy user).

my goal would be a code that's remove query string (".modal-close").click without reload the page, it's possible?

thanks

Valerio
  • 5
  • 1
  • 4
  • To my knowledge this is not possible. Changing the query string will always trigger a new request. Are you able to use `location.hash` instead (e.g. `http://www.example.com#modal`)? Changing the hash does not trigger a new page request. – Joseph Marikle Oct 13 '14 at 14:26
  • no, unfortunately i can't use hashes on my environment – Valerio Oct 13 '14 at 15:35

1 Answers1

0

I believe this question has already been answered several times before. Your modified code may look like:

 $(function() {
    $(".modal-close").click(function() {
        $("html").toggleClass("lightbox-is-open");
        $("html").toggleClass("lightbox-is-fixed");
        $(".dialog-container, .glasspane").fadeOut(200).addClass("hidden");
        setTimeout(function(){
            window.location.href = location.protocol + '//' + location.host + location.pathname;
        }, 200);
        return false;
    });
  });

Ref. How to get the URL without any parameters in JavaScript?

Note: Code has not been tested.

Community
  • 1
  • 1
user1477388
  • 20,790
  • 32
  • 144
  • 264
  • 1
    There's a key difference though. OP wants this functionality without causing a page refresh. – Joseph Marikle Oct 13 '14 at 14:26
  • 1
    Ahh, sorry; I didn't catch that. However, it seems that question, too, has been asked and answered before http://stackoverflow.com/questions/10700937/how-can-i-remove-the-query-string-from-the-url-after-the-page-loads Let my answer be a viable alternative if they wish to reconsider. – user1477388 Oct 13 '14 at 14:28
  • yeah, windows.location.href seems to work only with http requests.. i'm not able to find a way to do it without page reload – Valerio Oct 13 '14 at 15:37
  • Yep. I think that history API post that you linked to is what they are looking for – Clayton Leis Oct 13 '14 at 16:13