1 |
// These three functions are taken from code displayed on |
2 |
// http://www.netspade.com/articles/2005/11/16/javascript-cookies/ |
3 |
|
4 |
/** |
5 |
* Sets a Cookie with the given name and value. |
6 |
* |
7 |
* name Name of the cookie |
8 |
* value Value of the cookie |
9 |
* [expires] Expiration date of the cookie (default: end of current session) |
10 |
* [path] Path where the cookie is valid (default: path of calling document) |
11 |
* [domain] Domain where the cookie is valid |
12 |
* (default: domain of calling document) |
13 |
* [secure] Boolean value indicating if the cookie transmission requires a |
14 |
* secure transmission |
15 |
*/ |
16 |
function setCookie(name, value, expires, path, domain, secure) { |
17 |
document.cookie= name + "=" + escape(value) + |
18 |
((expires) ? "; expires=" + expires.toGMTString() : "") + |
19 |
((path) ? "; path=" + path : "") + |
20 |
((domain) ? "; domain=" + domain : "") + |
21 |
((secure) ? "; secure" : ""); |
22 |
} |
23 |
|
24 |
/** |
25 |
* Gets the value of the specified cookie. |
26 |
* |
27 |
* name Name of the desired cookie. |
28 |
* |
29 |
* Returns a string containing value of specified cookie, |
30 |
* or null if cookie does not exist. |
31 |
*/ |
32 |
function getCookie(name) { |
33 |
var dc = document.cookie; |
34 |
var prefix = name + "="; |
35 |
var begin = dc.indexOf("; " + prefix); |
36 |
if (begin == -1) { |
37 |
begin = dc.indexOf(prefix); |
38 |
if (begin != 0) return null; |
39 |
} else { |
40 |
begin += 2; |
41 |
} |
42 |
var end = document.cookie.indexOf(";", begin); |
43 |
if (end == -1) { |
44 |
end = dc.length; |
45 |
} |
46 |
return unescape(dc.substring(begin + prefix.length, end)); |
47 |
} |
48 |
|
49 |
/** |
50 |
* Deletes the specified cookie. |
51 |
* |
52 |
* name name of the cookie |
53 |
* [path] path of the cookie (must be same as path used to create cookie) |
54 |
* [domain] domain of the cookie (must be same as domain used to create cookie) |
55 |
*/ |
56 |
function deleteCookie(name, path, domain) { |
57 |
if (getCookie(name)) { |
58 |
document.cookie = name + "=" + |
59 |
((path) ? "; path=" + path : "") + |
60 |
((domain) ? "; domain=" + domain : "") + |
61 |
"; expires=Thu, 01-Jan-70 00:00:01 GMT"; |
62 |
} |
63 |
} |
64 |
|
65 |
// These two functions are based on code from |
66 |
// http://www.quirksmode.org/viewport/compatibility.html |
67 |
|
68 |
function getPageHeight(){ |
69 |
var y; |
70 |
var test1 = document.body.scrollHeight; |
71 |
var test2 = document.body.offsetHeight |
72 |
if (test1 > test2) // all but Explorer Mac |
73 |
{ |
74 |
y = document.body.scrollHeight; |
75 |
} |
76 |
else // Explorer Mac; |
77 |
//would also work in Explorer 6 Strict, Mozilla and Safari |
78 |
{ |
79 |
y = document.body.offsetHeight; |
80 |
} |
81 |
return parseInt(y); |
82 |
} |
83 |
|
84 |
function _getWindowHeight(){ |
85 |
var frameWidth; |
86 |
var frameHeight; |
87 |
if (self.innerWidth) |
88 |
{ |
89 |
frameWidth = self.innerWidth; |
90 |
frameHeight = self.innerHeight; |
91 |
} |
92 |
else if (document.documentElement && document.documentElement.clientWidth) |
93 |
{ |
94 |
frameWidth = document.documentElement.clientWidth; |
95 |
frameHeight = document.documentElement.clientHeight; |
96 |
} |
97 |
else if (document.body) |
98 |
{ |
99 |
frameWidth = document.body.clientWidth; |
100 |
frameHeight = document.body.clientHeight; |
101 |
} |
102 |
return parseInt(frameHeight); |
103 |
} |
104 |
|
105 |
|
106 |
function getScrollHeight(){ |
107 |
var y; |
108 |
// all except Explorer |
109 |
if (self.pageYOffset) |
110 |
{ |
111 |
y = self.pageYOffset; |
112 |
} |
113 |
else if (document.documentElement && document.documentElement.scrollTop) |
114 |
{ |
115 |
y = document.documentElement.scrollTop; |
116 |
} |
117 |
else if (document.body) // all other Explorers |
118 |
{ |
119 |
y = document.body.scrollTop; |
120 |
} |
121 |
return parseInt(y)+_getWindowHeight(); |
122 |
} |
123 |
|