Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

FirstTime = SignUp

Ok so basicly here is my script:

window.onload = () => {
enter code here if (first_time) {
window.location.href = "www.netlify.app/teamadventures.signup";
}
}

I want to make it so that if it’s your first time on the website you get taken to a signup page automatically. How do I do this with vanilla JS?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use cookies or localstorage for that. The localstorage is the easier method. First check if theres something stored on it with getItem. If not, store this information (the user visited the page) in local storage and redirect to the Sign Up.

var first_time = localStorage.getItem("first_time");

if (!first_time){
localStorage.setItem("first_time", 1);
window.location.href = "www.netlify.app/teamadventures.signup";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading