Answer the question
In order to leave comments, you need to log in
How to save cookies on all browsers?
Hi all! Created a static site for coursework. And on the site, I used javascript to save cookies and if the user is not logged into the site, he will be redirected to the login page.
The problem is this: Mozilla Firefox saves cookies and the site works fine. But on all other browsers, cookies are not saved. I tried to open the site through the local disk (file:///D:/Documents/CW/login.html) and through OpenServer ( site.ru/login.html).
Here is the js code:
function Login() {
if (document.getElementById('log').value == "User" && document.getElementById('pass').value == "User123") {
var cookie_date = new Date();
cookie_date.setFullYear(2018);
if (document.getElementById('save').checked == true){
document.cookie = "Logged=true; path=/; expires=" + cookie_date.toGMTString();
} else {
document.cookie = "Logged=true; path=/; expires=;";
}
document.getElementById("success").style.display = 'block';
window.setTimeout(function(){
window.location.href = "index.html";
}, 1000);
} else {
document.getElementById("error").style.display = 'block';
}
}
<form name="login">
<div class="logo">
<a class="logo_l" href=""></a>
</div>
<input type="text" maxlength="12" id="log" placeholder="Login" value="User">
<input type="password" maxlength="12" id="pass" placeholder="Password" value="User123">
<div class="last">
<input type="checkbox" id="save">
<label for="save" class="save">Keep me logged in</label>
<a onclick="Login()" class="login">Log in</a>
</div>
</form>
<span id="error">Login or password is not correct!</span>
<span id="success">You successfully logged in!</span>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question