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

这篇文章主要介绍了js不同客户端显示不同广告(pc端+移动端+微信端),比较适合自适应网站的广告,需要的朋友可以参考下

核心代码

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("
"); document.writeln("
"); document.writeln("
"); document.writeln(" "); document.writeln("
"); document.writeln("
"); document.writeln("
"); }

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

以上就是js不同客户端显示不同广告(pc端+移动端+微信端)的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程