<div align="center" class="navbar-brand-right col-sm-2" > <a href="http://ds.nfledmedia.com" style="color:white;" target="_blank" onclick="createCookies()" ><h4>动态报价系统 Go</h4></a> </div>
<script type="text/javascript"> var username='${request.username}'; var password='${request.password}'; function createCookies(){ var seconds = seconds || 0; //seconds has a value and is directly assigned, if not 0, this root php is different. var expires = ""; if (seconds != 0 ) { //Set cookie lifetime var date = new Date(); date.setTime(date.getTime()+(seconds*10)); expires = "; expires="+date.toGMTString(); } // document.cookie="name="+username+";path='/'"; var nameValue=username; var passwordValue=password; // var name="name"; document.cookie="name="+escape(nameValue)+expires+"; path=/"; // document.cookie="password="+escape(passwordValue)+expires+"; path=/"; } </script>
Get cookies:
function getCookie(name){ var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return arr[0]; else return null; }
Auto-login without doing anything when the login page loads:
function load(){ if(usernameAuto!=null&&usernameAuto!=""){ document.getElementById("username").value=usernameAuto;//Set the value of the element in the form document.getElementById("password").value="a"; document.getElementById("usernameAuto").value=usernameAuto; delCookie("name"); $("#btn-sub").click();//Trigger button click event, submit form, call User_login.action } }
<body style="font-family: '微软雅黑';" onload="load()">
Delete cookie: (ie overwrite the previous cookie, pay attention to the path range)
function delCookie(name){ var date=new Date(); date.setTime(date.getTime()+(-1 * 24 * 60 * 60 * 1000)); document.cookie=name+"= ; expire="+date.toGMTString()+"; path=/"; }