html - JAVASCRIPT log-in redirect with local storage -
i doing project on javascript , can't figure out 1 thing , how log-in , re direct user specific version of website. example, if not logged in can't use option on shopping website buy goods. when logged in option becomes available. task using local storage log-in. can use javascript on appreciated!
function store() { var name = document.getelementbyid('name'); var pw = document.getelementbyid('pw'); var telefon = document.getelementbyid('telefon') var email = document.getelementbyid('email') var adresa = document.getelementbyid('adresa') var drzava = document.getelementbyid('drzava') var mrod = document.getelementbyid('mrod') var zrod = document.getelementbyid('zrod') localstorage.setitem('name', name.value); localstorage.setitem('pw', pw.value); localstorage.setitem('telefon', telefon.value); localstorage.setitem('email', email.value); localstorage.setitem('adresa', adresa.value); } function check() { var storedname = localstorage.getitem('name'); var storedpw = localstorage.getitem('pw'); var username = document.getelementbyid('username'); var userpw = document.getelementbyid('userpw'); if(username.value == storedname && userpw.value == storedpw) { alert('you loged in.'); }else { alert('error.'); } }
body{ margin:0px; font:1em "open sans", sans-serif; } .content { padding:30px; } .nav-main{ background-color:#222; width:100%; color:#fff; height: 70px; } .nav-main .logo { float:left; height:40px; padding:15px 30px; font-size:2.4em; line-height:40px; } .nav-main > ul { margin:0px; padding:0px; float:left; list-style:none; } .nav-main > ul > li { float: left; } .nav-item { display:inline-block; padding:15px 20px; height: 40px; line-height:40px; color:white; text-decoration: none; } .nav-item:hover { background-color:#444 } .nav-content { position:absolute; top: 70px; overflow:hidden; background-color:#222; max-height:0; } .nav-content { color:white; text-decoration: none; } .nav-content a:hover { text-decoration:underline; } .nav-sub { padding:20px; } .nav-sub ul { padding: 0; margin: 0; list-style-type:none; } .nav-sub ul li { display:inline-block; padding:5px 0; } .nav-item:focus { background-color:#444; } .nav-item:focus ~ .nav-content { max-height:400px; -webkit-transition:max-height 0.4s ease-in; -moz-transition:max-height 0.4s ease-in; transition:max-height 0.4s ease-in; } h1 { margin-left: 70px; } form li { list-style: none; margin-bottom: 5px; } form ul li label{ float: left; clear: left; width: 100px; text-align: right; margin-right: 10px; font-family:verdana, arial, helvetica, sans-serif; font-size:14px; } form ul li input, select, span { float: left; margin-bottom: 10px; } form textarea { float: left; width: 350px; height: 150px; } [id="rgstr_btn"] { margin: none; margin: 230px -120px; font-size:12px } [id="login_btn"] { margin: none; margin: 58px -100px; font-size:12px } p { margin-left: 70px; font-weight: bold; }
<!doctype html> <html> <head> <meta charset="utf-8"> <title>registruj se</title> <link rel="stylesheet" href="style2.css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=open+sans"> </head> <body> <nav class="nav-main"> <div class="logo"><b>oglasi</b></div> <ul> <li> <a href="pocetna.html" class="nav-item">pocetna</a> </li> <li> <a href="kupovina.html" class="nav-item">kupovina</a> </li> <li> <a href="prodaja.html" class="nav-item">prodaja</a> </li> <li> <a href="#" class="nav-item">kategorije</a> <div class="nav-content"> <div class="nav-sub"> <ul> <li><a href="iphone.html">iphone</a></li> <li><a href="#">samsung</a></li> <li><a href="#">sony</a></li> </ul> </div> </div> </li> <li> <a href="registruj_se.html" class="nav-item">registruj se</a> </li> <li> <a href="uloguj_se.html" class="nav-item">uloguj se</a> </li> <li> <a href="moj_profil.html" class="nav-item">moj profil</a> </li> </ul> </nav> <form id="login-form"> <ul> <li><label for="enter username">korisnicki id:</label></li> <li><input id="username" type="text" placeholder="enter username" value=""/></li> <li><label for="enter password">sifra:</label></li> <li><input id="userpw" type="password" placeholder="enter password" value=""/></li> <li><button id="login_btn" type="button" value="login" onclick="check()"/>login</button></li> </ul> </form> <script type="text/javascript" language="javascript" src="1.js"></script> </body> </html>
`s.
you can use javascript location object send user page when there login no longer valid. location.assign("http://homepage/home.com");
Comments
Post a Comment