javascript codes
谷歌、火狐全屏:
1 addEventListener("click", function() { 2 var 3 el = document.documentElement 4 , rfs = el.webkitRequestFullScreen 5 || el.mozRequestFullScreen 6 ; 7 rfs.call(el); 8 });
离开网页时弹出
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 function ouibounce(el, config) { 2 var config = config || {}, 3 aggressive = config.aggressive || false, 4 sensitivity = setDefault(config.sensitivity, 20), 5 timer = setDefault(config.timer, 1000), 6 callback = config.callback || function() {}, 7 cookieExpire = setDefaultCookieExpire(config.cookieExpire) || '', 8 cookieDomain = config.cookieDomain ? ';domain=' + config.cookieDomain : '', 9 sitewide = config.sitewide === true ? ';path=/' : '', 10 _html = document.getElementsByTagName('html')[0]; 11 12 function setDefault(_property, _default) { 13 return typeof _property === 'undefined' ? _default : _property; 14 } 15 16 function setDefaultCookieExpire(days) { 17 // transform days to milliseconds 18 var ms = days*24*60*60*1000; 19 20 var date = new Date(); 21 date.setTime(date.getTime() + ms); 22 23 return "; expires=" + date.toGMTString(); 24 } 25 26 setTimeout(attachOuiBounce, timer); 27 function attachOuiBounce() { 28 _html.addEventListener('mouseleave', handleMouseleave); 29 _html.addEventListener('keydown', handleKeydown); 30 } 31 32 function handleMouseleave(e) { 33 if (e.clientY > sensitivity || (checkCookieValue('viewedOuibounceModal', 'true') && !aggressive)) return; 34 fire(); 35 callback(); 36 } 37 38 var disableKeydown = false; 39 function handleKeydown(e) { 40 if (disableKeydown || checkCookieValue('viewedOuibounceModal', 'true') && !aggressive) return; 41 else if(!e.metaKey || e.keyCode != 76) return; 42 43 disableKeydown = true; 44 fire(); 45 callback(); 46 } 47 48 function checkCookieValue(cookieName, value) { 49 // cookies are separated by '; ' 50 var cookies = document.cookie.split('; ').reduce(function(prev, curr) { 51 // split by '=' to get key, value pairs 52 var el = curr.split('='); 53 54 // add the cookie to fn object 55 prev[el[0]] = el[1]; 56 57 return prev; 58 }, {}); 59 60 return cookies[cookieName] === value; 61 } 62 63 function fire() { 64 // You can use ouibounce without passing an element 65 // https://github.com/carlsednaoui/ouibounce/issues/30 66 if (el) el.style.display = 'block'; 67 disable(); 68 } 69 70 function disable(options) { 71 var options = options || {}; 72 73 // you can pass a specific cookie expiration when using the OuiBounce API 74 // ex: _ouiBounce.disable({ cookieExpire: 5 }); 75 if (typeof options.cookieExpire !== 'undefined') { 76 cookieExpire = setDefaultCookieExpire(options.cookieExpire); 77 } 78 79 // you can pass use sitewide cookies too 80 // ex: _ouiBounce.disable({ cookieExpire: 5, sitewide: true }); 81 if (options.sitewide === true) { 82 sitewide = ';path=/'; 83 } 84 85 // you can pass a domain string when the cookie should be read subdomain-wise 86 // ex: _ouiBounce.disable({ cookieDomain: '.example.com' }); 87 if (typeof options.cookieDomain !== 'undefined') { 88 cookieDomain = ';domain=' + options.cookieDomain; 89 } 90 91 document.cookie = 'viewedOuibounceModal=true' + cookieExpire + cookieDomain + sitewide; 92 93 // remove listeners 94 _html.removeEventListener('mouseleave', handleMouseleave); 95 _html.removeEventListener('keydown', handleKeydown); 96 } 97 98 return { 99 fire: fire, 100 disable: disable 101 }; 102 }