Removing duplicates from a URL before refreshing a page

After the new user registers, I need to redirect the user to the home page and display a Twitter-style welcome message. At first I tried to use the jquery cookie plugin to store my message and display it on a redirected page if a cookie is present, but the problem is that it does not work in all browsers. Firfox on Safari does not delete the cookie, so the message continues to be displayed every time the browser is updated. Here is the code:

if ($.cookie("message")) {
    TwentyQuestions.Common.ShowMessageBar($.cookie("message"), 7000);
    $.cookie('message', "any_value", { expires: -10 })
}

So, I decided to use querystring instead, but now the problem is similar. When the home page loads, a query string is detected and a message is displayed. But how to remove the query string from the URL so that the message does not appear every time the page is refreshed?

Thank!

+3
source share
5 answers

Perhaps the problem is that you are trying to do everything on the client side. Instead, you should set a persistent cookie associated with the user. Then, in the background, the first time you access this page, the home page is displayed. Also clear the first time flag for this server-side user. Then, the next time the user visits this page, they will not see the message.

, , cookie , " ".

+1

:

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

, , , ?

+5

querystring .

, .

- :

if(document.location.hash == '<special hash>') {
    TwentyQuestions.Common.ShowMessageBar(...);
    document.location.hash='';
}
+1
location = location.pathname + location.hash

, , POST-, , , , GET.

, .

0

cookie, cookie . , , , cookie jQuery cookie - null; :

@example $.cookie('the_cookie', null); @desc cookie, null . , , cookie.

:

$.cookie('message', null);

cookie .

0

All Articles