js不同客户端显示不同广告(pc端+移动端+微信端)

Serafina ·
更新时间:2024-09-20
· 395 次阅读

核心代码

var IsSpider=/spider|bot/ig.test(window.navigator.userAgent); var IsMobile=/ipad|iphone|ipod|android|mobile/ig.test(window.navigator.userAgent); var IsWeixin=/micromessenger/i.test(window.navigator.userAgent); var i; web=[]; mob=[]; wex=[]; // 提问头部 web['single_question_banner']='pc端广告代码'; mob['single_question_banner']='移动端广告代码'; wex['single_question_banner']='微信端广告代码'; // 标题头部 web['single_question_bottom']=''; mob['single_question_bottom']=''; wex['single_question_bottom']=''; if (IsMobile) { for (i in web) { web[i] = mob[i]; } } function growing(id) { if(IsSpider)return; document.writeln(web[id]); }

具体的代码大家自行参考。代码比较简单,主要是通过数组定义广告代码。

js如何实现广告在pc端显示,移动端不显示 var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, presto: u.indexOf('Presto') > -1, webKit: u.indexOf('AppleWebKit') > -1, gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), android: u.toLowerCase().indexOf('android') > -1 , iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, iPad: u.indexOf('iPad') > -1, webApp: u.indexOf('Safari') == -1 }; }() } if (!(browser.versions.android || browser.versions.ios || browser.versions.iPhone || browser.versions.iPad)){ document.writeln("<div class=\'float_layer\' id=\'miaov_float_layer\' style=\'z-index:10001;\'>"); document.writeln(" <div class=\'content\'>"); document.writeln(" <div class=\'wrap\'> "); document.writeln(" <a href=\'http://yookee.cc/\' target=\'_blank\'><img src=\'/ad1/14690989051188.gif\' width=\'300\' height=\'250\' /></a>"); document.writeln(" </div>"); document.writeln(" </div>"); document.writeln("</div>"); }

到此这篇关于js不同客户端显示不同广告(pc端+移动端+微信端)的文章就介绍到这了,更多相关js不同客户端显示不同广告内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!



微信 客户端 广告 js

需要 登录 后方可回复, 如果你还没有账号请 注册新账号