Home and Blog button

Pages

Introduction

Welcome To my Blog !!
This is a blog where you can get some knowledge that i have learned and been using. Sharing is gaining pals. So Happy Sharing and don't forget to follow and link my blog with yours! Thanks.
Happy Programming!!

Tuesday, July 7, 2009

How to use Cookies in browsers using VBScript?

Do you love Cookies?

The cookie is a small amount of data which is given a name and stores by browser in the clients computer. It is associated with a webpage or website and it can be used to save states of the webpage. For Example:
  1. Saving user preferences.
  2. Recalling user preferences.
  3. Saving and recalling state information.
  4. Enables informations to be accessed by multiple web pages.
Cookies can be written or read by VBScripts, CGI scripts and javascript. Here given below is an example to save to and retrive the cookie from the browser's computer.

Saving Cookies to Eat!!

Write Cookie to Save: Display Saved Cookie:
Source Code:


<html> 
<head>
<title>vbscript - Save Cookies!</title>
<script language =vbscript> 
Sub bttnSave_OnClick() 
If not document.form1.txtcookie.value = "" Then 
document.cookie = document.form1.txtcookie.value 
msgbox("Cookies Saved Successfully!!") 
Else
msgbox("Write data first!") 
End If 
End Sub 

Sub bttnDisplay_OnClick() 
document.form1.txtres.value = document.cookie
End Sub

</script>
</head> 
<body> 

<form name="form1"> 
<b>Saving Cookies to Eat!!</b><br>
<hr> 
Write Cookie to Save:&nbsp <input type="text" name="txtcookie" value=""> <input type="button" name="bttnSave" value="Save Cookie"><br> 
Display Saved Cookie: <input type="text" name="txtres" value=""> <input type="button" name="bttnDisplay" value="Display Cookie"><br> <input type="Reset" name="Reset" value="Clear"><br> 
</form> 
</body> 
</html>

No comments:

Post a Comment

Search This Blog