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

2
  • 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. Commented Oct 13, 2014 at 14:26
  • no, unfortunately i can't use hashes on my environment Commented Oct 13, 2014 at 15:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

There's a key difference though. OP wants this functionality without causing a page refresh.
Ahh, sorry; I didn't catch that. However, it seems that question, too, has been asked and answered before stackoverflow.com/questions/10700937/… Let my answer be a viable alternative if they wish to reconsider.
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
Yep. I think that history API post that you linked to is what they are looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.