0

Hi I have am logging in users and redirecting them to http://domain.com/profile/#welcomemessage or http://domain.com/profile/?msg=showwelcomemessage

So basically it shows welcome message based on query string.When Users reload the page I want to remove the query.i.e..basically I want to show the welcome message only once.

If this is not possible.Should I use localstorage ? will this work on all browsers?

asked Apr 10, 2015 at 18:07

2 Answers 2

2

You are probably looking for

window.history.replaceState

Usage:

window.history.replaceState( {} , 'foo', '/foo' );

From w3.org:

history . replaceState(data, title [, url ] )

Updates the current entry in the session history to have the given data, title, and, if provided and not null, URL.

or you can use localStorage like this:

if (!localStorage.getItem("visited")) {
 //yourmessage
 localStorage.setItem("visited", "true");
}
//clear the localStorage when the tab is closed
window.onbeforeunload = function() {
 localStorage.removeItem("visited");
};
answered Apr 10, 2015 at 18:13
Sign up to request clarification or add additional context in comments.

Comments

1

localStorage sounds like the way to go. Or a session if you are more server-orientated. localStorage does work in ie8 and above

For localStorage:

if (!localStorage.hideWelcomeMessage) {
 document.getElementById('welcome-message').style.display="block";
 localStorage.hideWelcomeMessage = true;
}

and html:

<div id="welcome-message" style="display:none;">Welcome!</div>

The above assumes the id is "welcome-message" but of course you can change that up.

answered Apr 10, 2015 at 18:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.