Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <!--
- any browser sniffing tool you care to employ will do -
- I used Mark Wilton-Jones' sniffer.js:
- http://www.howtocreate.co.uk/jslibs/sniffer.js
- -->
- <script type="text/javascript" src="sniffer.js"></script>
- <script type="text/javascript">
- function getCookie(key) {
- // convenience reference
- var c = document.cookie;
- // if none, return null - exit immediately
- if ( 0 == c.length ) return null;
- // implicit else - test for cookie value for key
- var cv_start = c.indexOf(key + "=");
- // if no value for key, return null - exit immediately
- if (-1 == cv_start) return null;
- // implicit else - get value from cookie string
- var cv = c.substring(cv_start + (key + "=").length);
- // find end of value for key
- var cv_end = cv.indexOf( ";" );
- // if no trailing semi-colon, this is last value, reset end
- if ( -1 == cv_end ) cv_end = cv.length;
- // chop trailing parts, if any and return unescaped value
- return unescape( cv.substring( 0, cv_end ) );
- };
- function setCookie( key, value, expiredays) {
- // if not given, set default number of days until expiration
- // to one year in the future
- if ('undefined' == typeof expiredays) expiredays = 365.25;
- // get a new Date instance
- var expires = new Date();
- // convert requested (or default) number of days to milliseconds
- expires.setTime( expires.getTime() + 1000*24*60*60 * expiredays );
- // add new key/value pair to cookies for page
- document.cookie = key + '=' + escape(value) +
- ((null == expiredays)?'':(';expires=' + expires.toGMTString()));
- };
- function getString( p ) {
- while (true) {
- var str = prompt( p, '' );
- if (0 < str.length) break;
- else alert( 'input must not be empty - try again' );
- }
- return str;
- };
- function storeUserData() {
- setCookie( 'name', getString( 'enter user name' ));
- setCookie( 'mail', getString( 'enter email account' ));
- setCookie( 'browser', yourBro[1]);
- };
- function showUserData() {
- var rpt = 'name: ' + getCookie( 'name' );
- rpt += ' - mail: ' + getCookie( 'mail' );
- rpt += ' - browser: ' + getCookie( 'browser' );
- alert( rpt );
- };
- </script>
- </head>
- <body>
- <form>
- <p>
- <input type="button" value="store cookie data"
- onclick="storeUserData()" />
- <input type="button" value="show cookie data"
- onclick="showUserData()" />
- </p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement