home *** CD-ROM | disk | FTP | other *** search
/ PC User 2005 May / CD / PCU0505CD.iso / software / full / coffecup / files / html2005.exe / %MAINDIR% / Javascript / popup-only-once.xml < prev    next >
Encoding:
Text File  |  2005-02-16  |  2.9 KB  |  115 lines

  1.  
  2. <ccresource>
  3.   <cctitle>
  4. One Time Pop Up Window
  5.   </cctitle>
  6.   <cccategory>
  7. Browser
  8.   </cccategory>
  9.   <ccDescription>
  10.     This code will allow you to only present a pop-up window once per unique visitor.
  11.   </ccdescription>
  12.   <ccinstructions>
  13.   The code goes both within the HEAD and BODY tags.  You need to create another webpage labeled only-popup-once.html.
  14.   You can make the adjustments below on the actual filename if different from suggested one.  Also you can change the
  15.   size of the pop-up window and how long the cookie should remain on the visitor's computer.
  16.   </ccinstructions>
  17.   <ccheadcontent>
  18. <SCRIPT LANGUAGE="JavaScript">
  19.  
  20.  
  21. <!-- Begin
  22. var expDays = 1; // number of days the cookie should last
  23.  
  24. var page = "only-popup-once.html";
  25. var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
  26.  
  27. function GetCookie (name) {
  28. var arg = name + "=";
  29. var alen = arg.length;
  30. var clen = document.cookie.length;
  31. var i = 0;
  32. while (i < clen) {
  33. var j = i + alen;
  34. if (document.cookie.substring(i, j) == arg)
  35. return getCookieVal (j);
  36. i = document.cookie.indexOf(" ", i) + 1;
  37. if (i == 0) break;
  38. }
  39. return null;
  40. }
  41. function SetCookie (name, value) {
  42. var argv = SetCookie.arguments;
  43. var argc = SetCookie.arguments.length;
  44. var expires = (argc > 2) ? argv[2] : null;
  45. var path = (argc > 3) ? argv[3] : null;
  46. var domain = (argc > 4) ? argv[4] : null;
  47. var secure = (argc > 5) ? argv[5] : false;
  48. document.cookie = name + "=" + escape (value) +
  49. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  50. ((path == null) ? "" : ("; path=" + path)) +
  51. ((domain == null) ? "" : ("; domain=" + domain)) +
  52. ((secure == true) ? "; secure" : "");
  53. }
  54. function DeleteCookie (name) {
  55. var exp = new Date();
  56. exp.setTime (exp.getTime() - 1);
  57. var cval = GetCookie (name);
  58. document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  59. }
  60. var exp = new Date();
  61. exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  62. function amt(){
  63. var count = GetCookie('count')
  64. if(count == null) {
  65. SetCookie('count','1')
  66. return 1
  67. }
  68. else {
  69. var newcount = parseInt(count) + 1;
  70. DeleteCookie('count')
  71. SetCookie('count',newcount,exp)
  72. return count
  73.    }
  74. }
  75. function getCookieVal(offset) {
  76. var endstr = document.cookie.indexOf (";", offset);
  77. if (endstr == -1)
  78. endstr = document.cookie.length;
  79. return unescape(document.cookie.substring(offset, endstr));
  80. }
  81.  
  82. function checkCount() {
  83. var count = GetCookie('count');
  84. if (count == null) {
  85. count=1;
  86. SetCookie('count', count, exp);
  87.  
  88. window.open(page, "", windowprops);
  89.  
  90. }
  91. else {
  92. count++;
  93. SetCookie('count', count, exp);
  94.    }
  95. }
  96. //  End -->
  97. </script>
  98.   </ccheadcontent>
  99.   <ccbodycontent>
  100.  
  101. <body OnLoad="checkCount()">
  102.  
  103.  
  104.   </ccbodycontent>
  105.   <ccelementcontent>
  106.   
  107.    <ccelementname></ccelementname>
  108.    <ccelementaction></ccelementaction>
  109.    
  110.   </ccelementcontent>
  111.   <ccextradata>
  112.  
  113.   </ccextradata>
  114. </ccresource>
  115.