SoFunction
Updated on 2025-04-07

Set cookie specified time invalid (instance code)

Set cookie specified time invalid (instance code)

Updated: May 28, 2017 10:50:50   Submission: jingxian
Below, the editor will bring you an article setting the specified time invalidation of cookies (example code). The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor

Examples are as follows:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			// Set cookies to expire at the specified time point on the day and prompt			function setCookie(name,value,Deadline){
				// Get the current date object				var curDate = new Date();
				// Get the time stamp corresponding to the current date				var curTime = ();
				// Get the time stamp of the specified time				var endTime = convertTime(curDate,Deadline);
				// Calculate the time difference between the specified time and the current time				var disTime = endTime - curTime;
				// Set the cookie expiration time			  var exp = new Date(); 
			  (endTime);//Expiration time				 = name + '=' + value + ';expires=' + ();
			}
			//Get cookies			function getCookie(c_name){
			if (>0)
			 {
			 c_start=(c_name + "=")
			 if (c_start!=-1)
			  { 
			  c_start=c_start + c_name.length+1 
			  c_end=(";",c_start)
			  if (c_end==-1) c_end=
			  return unescape((c_start,c_end))
			  } 
			 }
			return ""
			}
			
			// Get the time stamp of the specified time			function convertTime(nowDate,Deadline){
				// Split parameter Deadline				var _dateArr = (':');
				// Get the corresponding hours, minutes and seconds in the parameters respectively				var hours = parseInt(_dateArr[0]);
				var minutes = parseInt(_dateArr[1]);
				var seconds = parseInt(_dateArr[2]);
				// Set the corresponding time, minute and second				(hours); 
				(minutes); 
				(seconds);
				// Get the number of milliseconds corresponding to the specified time, minute and second in the current day				var result = (nowDate);
				return result;
			}
			//If the cookie does not exist or expires, execute			if(getCookie('uvsize')==""){
				setCookie('uvsize','uvsize','24:00:00');
				var imgadd=("img");
				(imgadd);
				="http://123.56.49.26:8090/assets/?a=1";
				="none";
			}
		</script>
	</head>
	<body>
		
	</body>
</html>

The above article setting the specified time invalidation of cookies (example code) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.

  • cookie
  • Time of failure
  • set up

Related Articles

  • Mini Program Development page-container page-container page container pop-up dialog function

    This article mainly introduces the mini program development page-container page container, and a dialog box pops up. This article introduces you very detailed through sample code, which has certain reference value for your study or work. Friends who need it can refer to it.
    2022-08-08
  • js function usage experience

    JS function usage experience is a good reference for object-oriented learning.
    2010-05-05
  • Three ways to dynamically generate unique ids by js

    This article mainly introduces two methods of dynamically generating unique ids by js. Friends who need it can refer to it
    2023-05-05
  • Pure JS single page racing game production code sharing

    This article mainly shares the pure JS single-page racing game production code for everyone, which has certain reference value. Interested friends can refer to it.
    2017-03-03
  • WeChat applet realizes tab page switching function

    This article mainly introduces the WeChat applet to realize the tab page switching function. The code is simple and easy to understand, very good, and has certain reference value. Friends who need it can refer to it.
    2018-07-07
  • How to use store data sharing in WeChat applets

    Global data sharing Global data sharing (state management) is to solve the problem of data sharing among components. Commonly used global data sharing solutions in development include: Vuex, Redux, MobX, etc. This article mainly introduces how to use store data sharing in WeChat applets. Friends who need it can refer to it.
    2023-04-04
  • Detailed explanation of the use of Bootstrap modal box plug-in

    This article mainly introduces the use of Bootstrap modal box plug-in in detail, which has certain reference value. Interested friends can refer to it.
    2017-05-05
  • Introduction to the properties and methods of XMLHTTPRequest

    Since you are now responsible for making standard static pages in the company, in order to enhance the customer experience, you often have to do some AJAX effects. Maybe you are like me, learning AJAX.
    2010-11-11
  • The difference between

    The value is often different.
    2009-05-05
  • A brief analysis of Bootstrap thumbnail component and warning box component

    The most commonly used thumbnails on websites is the product list page, which displays several pictures in one line, and some have titles, description content, buttons and other information under the pictures. This article introduces Bootstrap thumbnail component and warning box component to you. Interested friends can learn together
    2016-04-04

Latest Comments