Advertisement
Guest User

popunder

a guest
Jan 30th, 2012
1,626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var puShown = false;
  2. var PopWidth = 10;
  3. var PopHeight = 10;
  4. var PopFocus = 0;
  5. var _Top = null;
  6.  
  7. function GetWindowHeight() {
  8. var myHeight = 0;
  9. if( typeof( _Top.window.innerHeight ) == 'number' ) {
  10. myHeight = _Top.window.innerHeight;
  11. } else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
  12. myHeight = _Top.document.documentElement.clientHeight;
  13. } else if( _Top.document.body && _Top.document.body.clientHeight ) {
  14. myHeight = _Top.document.body.clientHeight;
  15. }
  16. return myHeight;
  17. }
  18.  
  19. function GetWindowWidth() {
  20. var myWidth = 0;
  21. if( typeof( _Top.window.innerWidth ) == 'number' ) {
  22. myWidth = _Top.window.innerWidth;
  23. } else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
  24. myWidth = _Top.document.documentElement.clientWidth;
  25. } else if( _Top.document.body && _Top.document.body.clientWidth ) {
  26. myWidth = _Top.document.body.clientWidth;
  27. }
  28. return myWidth;
  29. }
  30.  
  31. function GetWindowTop() {
  32. return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
  33. }
  34.  
  35. function GetWindowLeft() {
  36. return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
  37. }
  38.  
  39. function doOpen(url)
  40. {
  41. var popURL = "about:blank"
  42. var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
  43. var pxLeft = 0;
  44. var pxTop = 0;
  45. pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
  46. pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
  47.  
  48. if ( puShown == true )
  49. {
  50. return true;
  51. }
  52.  
  53. var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
  54.  
  55. if (PopWin)
  56. {
  57. puShown = true;
  58.  
  59. if (PopFocus == 0)
  60. {
  61. PopWin.blur();
  62.  
  63. if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
  64. {
  65. _Top.window.blur();
  66. _Top.window.focus();
  67. }
  68. }
  69.  
  70. PopWin.Init = function(e) {
  71.  
  72. with (e) {
  73.  
  74. Params = e.Params;
  75. Main = function(){
  76.  
  77. if (typeof window.mozPaintCount != "undefined") {
  78. var x = window.open("about:blank");
  79. x.close();
  80.  
  81. }
  82.  
  83. var popURL = Params.PopURL;
  84.  
  85. try { opener.window.focus(); }
  86. catch (err) { }
  87.  
  88. window.location = popURL;
  89. }
  90.  
  91. Main();
  92. }
  93. };
  94.  
  95. PopWin.Params = {
  96. PopURL: url
  97. }
  98.  
  99. PopWin.Init(PopWin);
  100. }
  101.  
  102. return PopWin;
  103. }
  104.  
  105. function setCookie(name, value, time)
  106. {
  107. var expires = new Date();
  108.  
  109. expires.setTime( expires.getTime() + time );
  110.  
  111. document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
  112. }
  113.  
  114. function getCookie(name) {
  115. var cookies = document.cookie.toString().split('; ');
  116. var cookie, c_name, c_value;
  117.  
  118. for (var n=0; n<cookies.length; n++) {
  119. cookie  = cookies[n].split('=');
  120. c_name  = cookie[0];
  121. c_value = cookie[1];
  122.  
  123. if ( c_name == name ) {
  124. return c_value;
  125. }
  126. }
  127.  
  128. return null;
  129. }
  130.  
  131. function initPu()
  132. {
  133.  
  134. _Top = self;
  135.  
  136. if (top != self)
  137. {
  138. try
  139. {
  140. if (top.document.location.toString())
  141. _Top = top;
  142. }
  143. catch(err) { }
  144. }
  145.  
  146. if ( document.attachEvent )
  147. {
  148. document.attachEvent( 'onclick', checkTarget );
  149. }
  150. else if ( document.addEventListener )
  151. {
  152. document.addEventListener( 'click', checkTarget, false );
  153. }
  154. }
  155.  
  156. function checkTarget(e)
  157. {
  158. if ( !getCookie('popundr') ) {
  159. var e = e || window.event;
  160. var win = doOpen('http://demo-site.com');
  161.  
  162. setCookie('popundr', 1, 12*60*60*1000);
  163. }
  164. }
  165.  
  166. initPu();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement