Javascript Cookie
Hej.Jeg skal bruge en funktion der opretter en cookie via et javascript.
Den skal give cookien et fast defineret navn og udfylde den med en nøgle ud fra et tekst felt som brugeren skal udfylde.
Har nu forsøgt med flere forskellige ting, men kan ikke få den til at kalde min funktion ordentligt.
Er der en der vil prøve og se hvad der er galt med nedenstående.
Har i nedenstående forsøgt at oprette 2 forskellige knapper og en til at hente cookien igen. Men ingen af dem virker.
Det bliver lavet i aspx til brug i sharepoint.
<%@ Page Language="C#" %>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head runat="server">
<META name="WebPartPageExpansion" content="full">
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture><mso:PublishingContact msdt:dt="string"></mso:PublishingContact></mso:CustomDocumentProperties></xml><![endif]-->
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture></mso:CustomDocumentProperties></xml><![endif]-->
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture></mso:CustomDocumentProperties></xml><![endif]-->
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture></mso:CustomDocumentProperties></xml><![endif]-->
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture></mso:CustomDocumentProperties></xml><![endif]-->
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture><mso:PublishingContact msdt:dt="string"></mso:PublishingContact></mso:CustomDocumentProperties></xml><![endif]-->
<meta http-equiv="Content-Language" content="da">
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string">, </mso:PublishingContactPicture><mso:PublishingContact msdt:dt="string"></mso:PublishingContact></mso:CustomDocumentProperties></xml><![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ny side1</title>
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else
var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
</script>
</head>
<body>
<input name="Text1" type="text" />
<script type="text/javascript">createCookie('cookienavn',Text1)</script>
<input type="button" value="Run Function" onclick="createCookie('cookienavn',Text1);" />
<input type="button" onclick="java script:return createCookie('navn','test');" />
<input type="button" onclick="java script:return readCookie();" />
</body>
</html>