群学会   >   网络  >  正文

网站随机切换广告代码

网站如何实现刷下页面自动切换图片广告,小编也是寻找和测试了很久才寻找到,那么下面小编为你分享两种随机切换广告代码

代码一:这种代码形式是正对长按扫码方式,针对网站自动切换各种二维码形式所用的,代码如下,仅需复制把图片链接改成你自己的即可

<script language=javascript>

today=new Date();

jran=today.getTime();

function rnd() {

ia=9301;

ic=49297;

im=233280;

jran = (jran*ia+ic) % im;

return jran/(im*1.0);

};

function rand(number) {

return Math.ceil(rnd()*number);

};

document.write("<center>");

for(i=1;i<=1;i++) {

mynum=(rand(10)); //随机图片;

if(mynum == 1) document.write("<img src='https://mp.qunxuehui.com/images/01.png'style=' width:100%; height:x;'/>"); 

if(mynum == 2) document.write("<img src='https://mp.qunxuehui.com//images/02.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 3) document.write("<img src='https://mp.qunxuehui.com//images/03.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 4) document.write("<img src='https://mp.qunxuehui.com//images/04.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 5) document.write("<img src='https://mp.qunxuehui.com//images/05.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 6) document.write("<img src='https://mp.qunxuehui.com//images/06.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 7) document.write("<img src='https://mp.qunxuehui.com//images/07.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 8) document.write("<img src='https://mp.qunxuehui.com//images/08.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 9) document.write("<img src='https://mp.qunxuehui.com//images/09.jpg'style=' width:100%; height:x;'/>"); 

if(mynum == 10) document.write("<img src='https://mp.qunxuehui.com//images/10.png'style=' width:100%; height:x;'/>"); 

else {

document.write();

}

};

document.write("</center>");

//-->

</script>

代码二:这种代码是正对广告图片点击的,只复制把图片链接地址改成你自己的即可,下列代码当用户刷新一次,就会自动切换广告图片以及链接,让网站实现多广告变现

<script language=javascript>

today=new Date();

jran=today.getTime();

function rnd() {

ia=9301;

ic=49297;

im=233280;

jran = (jran*ia+ic) % im;

return jran/(im*1.0);

};

function rand(number) {

return Math.ceil(rnd()*number);

};

document.write("<center>");

for(i=1;i<=1;i++) {

mynum=(rand(10)); //随机图片;

if(mynum == 1) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2021/08-24/9aebd2356a4f432909614af9aea0cf58.jpeg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 2) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2021/08-25/38b4deb26212cf38131cb3efa20bd470.jpeg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 3) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2021/01-10/486162efe36aa9cf66935e2159e5b30d.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 4) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2021/01-09/3c4f606584ce52a81816e2ea2c991fef.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 5) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/12-24/1be65a462b3cb3af8b9a2fa0ce15659e.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 6) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/12-08/fb38d678a4e34cb8187fded85e6fd889.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 7) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/12-08/fb38d678a4e34cb8187fded85e6fd889.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 8) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/07-11/b845501fca9dd117b912721ab4201181.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 9) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/04-26/002442a542f907ada4efd7cca5e8fd0d.jpg'style=' width:100%; height:x;'/></img></a>"); 

if(mynum == 10) document.write("<a href =https://www.qunxuehui.com/ ><img src='https://www.qunxuehui.com/d/file/p/2020/01-08/95f4b561c13f89bcf278a17586a32b12.jpg'style=' width:100%; height:x;'/></img></a>"); 

else {

document.write();

}

};

document.write("</center>");

//-->

</script>

ICP备案:粤ICP备18127096号 群学会 All Rights Reserved