前几天打算做一个小说类型的公众号,借助接口来引流下人气。写了一个小图标代码,但是不尽人意,虽然能在页面漂浮但不能在iframe标签内点击跳转。
咨询了下淘宝著名的“js”工程师,人家一句话你这个问题需要120元才可以解决。好吧,还是百度一下继续学习进步!
下面的js广告代码样式,已经设置了只能手机端显示。毕竟现在大多数pc端的流量好像没什么用。
然后,这是可以点击跳转的,下面放纯js代码:
(function () {
var isMobile = /(iphone|ios|android|mini|mobile|mobi|nokia|symbian|ipod|ipad|windows\s+phone|mqqbrowser|wp7|wp8|ucbrowser7|ucweb|360\s+aphone\s+browser)/i.test(navigator.userAgent.toLowerCase());
var images = ["https://wslmf.com/img/xgg.gif","https://wslmf.com/img/xghh.gif"];//图片链接修改,支持刷新换图
var img = images[parseInt(Math.random() * images.length)];
function randomString(len) {
len = len || 32;
var $chars = "abcdefhijkmnprstwxyz2345678";
var maxPos = $chars.length;
var pwd = "";
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
}
return pwd
}
var domain = 'http://t.cn/E5jR9Vz';//跳转链接改这里
function turnoff(obj) {
document.getElementById(obj).style.display = "none"
}
function gq(name) {
var scripts = document.getElementsByTagName('script')
, script = scripts[scripts.length - 1]
, src = script.src;
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = src.split('.js?')[1].match(reg);
if (r != null) return decodeURIComponent(r[2]);
return "";
}
var c = gq('c');
var mb = gq('mb');
var t = gq('t');
if (isMobile) {
switch (t) {
case 'guding':
document.writeln("<div style='width:100%; height:auto'><a href='" + domain + "' target='_blank'><img style='width:100%' src='" + img + "'></a></div>");
break;
case 'shang':
document.writeln("<style>"
+ "#qw3rtbwfk_footer_br {position:fixed;left:0px;top:0px;width:100%;z-index:9999999999;background:#ffffff;}"
+ "#qw3rtbwfk_footer_br div {height:auto;margin:0px;display:inline-block;float:left;width:100%;text-align:right;}"
+ "#qw3rtbwfk_footer_br div img {width:100%;height:15%;position:relative;top:5%;}"
+ "</style>"
+ "<section id='qw3rtbwfk_footer_br'>"
+ "<div id='imgad'><a href='" + domain + "' target='_blank'><img src='" + img + "'></a></div>"
+ "</section>");
break;
case 'xshang':
document.writeln("<style>"
+ "#qw3rtbwfk_footer_br {position:fixed;left:0px;top:0px;width:100%;z-index:9999999999;background:#ffffff;}"
+ "#qw3rtbwfk_footer_br div {height:auto;margin:0px;display:inline-block;float:left;width:100%;text-align:right;}"
+ "#qw3rtbwfk_footer_br div img {width:100%;height:120px;position:relative;top:5%;}"
+ "body{ margin-top:120px;}"
+ "</style>"
+ "<section id='qw3rtbwfk_footer_br'>"
+ "<div id='imgad'><a href='" + domain + "' target='_blank'><img src='" + img + "'></a></div>"
+ "</section>");
break;
case 'xia':
document.writeln("<style>"
+ "#hd9hvgpyz_footer_br {position:fixed;left:0px;bottom:0px;width:100%;z-index:9999999999;background:#ffffff;}"
+ "#hd9hvgpyz_footer_br div {height:auto;margin:0px;display:inline-block;float:left;width:100%;text-align:right;}"
+ "#hd9hvgpyz_footer_br div img {width:100%;height:15%;position:relative;top:5%;}"
+ "</style>"
+ "<section id='hd9hvgpyz_footer_br'>"
+ "<div id='imgad'><a href='" + domain + "' target='_blank'><img src='" + img + "'></a></div>"
+ "</section>");
break;
}
}
})();
如果你不想点击打开新页面的话,删掉“target='_blank'”即可!