(X)HTML, JavaScript, DHTML, XML, CSS Client scripting tehnologije, Dynamic HTML, Cascading Stylesheets, XML i standardi |
|
Alati teme | Način prikaza |
28. 02. 2013. | #1 |
član
Certified
Datum učlanjenja: 06.09.2012
Poruke: 64
Hvala: 0
342 "Hvala" u 10 poruka
|
Javascript cookies
Imam jedan problem sa cookie-em, kod radi Internet Exploreru, Mozili, Operi, al ne radi Google Chrom-u, napravio sam da se reklama svaki put promeni kad se refresuje stranica, jel ima neko neko resenje kod je sledeci:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script language="javascript" type="text/ecmascript"> function getCookieValue(cookieName) { var cookieValue = document.cookie; var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "="); if (cookieStartsAt == -1) { cookieStartsAt = cookieValue.indexOf(cookieName + "="); } if (cookieStartsAt == -1) { cookieValue = null; } else { cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1; var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt); if (cookieEndsAt == -1) { cookieEndsAt = cookieValue.length; } cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt)); } return cookieValue; } function setCookie(cookieName,cookieValue, cookiePath, cookieExpires) { cookieValue = escape(cookieValue); if (cookieExpires == "") { var nowDate = new Date(); nowDate.setMonth(nowDate.getMonth() + 6); cookieExpires = nowDate.toGMTString(); } if (cookiePath != "") { cookiePath = ";Path=" + cookiePath; } document.cookie = cookieName + "=" + cookieValue + ";Expires=" + cookieExpires + cookiePath; } </script> </head> <body> <img src="sl/AdvertImage1.jpg" name="imgAdvert"> <script> var imageNumber = getCookieValue("displayedImages"); var totalImages = 3; if (imageNumber == null) { imageNumber = "1"; } else { imageNumber = Math.floor(imageNumber) + 1; } if (totalImages == imageNumber) { setCookie("displayedImages","","","Mon, 1 Jan 1970 00:00:00"); } else { setCookie("displayedImages",imageNumber,"",""); } document.imgAdvert.src = "sl/AdvertImage" + imageNumber + ".jpg"; </script> </body> </html> |
|
|