JS对联广告代码(左侧对联、右侧对联)

相信很多人知道,现在JavaScript对联广告代码仅靠一些第方广告联盟去生成,似乎是很难了。很多的广告平台都去掉了JavaScript对联广告代码,我们这些站长只能自己来用JavaScript写一个对联广告代码喽,也是非常的简单;

 

1、html代码

duilian.js是我们调用的JS对联广告代码,后面有一个“?及相关参数”代码是指此JS不让缓存的意思;也可以不跟,看你的需求而定;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./duilian.js?so=fujieace"></script>
   
</head>
<body>
<p>JS对联广告代码(左侧对联、右侧对联)</p>
</body>
</html>

 

2、duilian.js代码

下面代码中的"style"样式可以自己根据自己需求来修改,a标签链接和img图片地址也可以随意修改成你自己想要的。

//左侧对联
document.write("<DIV  style='position:fixed;float:left;left:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
//右侧对联
document.write("<DIV  style='position:fixed;float:right;right:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");

有时候我们需要判断宽度来显示,可以用以下代码:

//获取分辨率宽度
var iScreenWidth = window.screen.width;
if(iScreenWidth > 1300){
	//左侧对联
    document.write("<DIV  style='position:fixed;float:left;left:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
    //右侧对联
    document.write("<DIV  style='position:fixed;float:right;right:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
 }

 

 

3、JS对联广告代码效果

由于我的这两张图片选择不是很好,可能效果不是很好看,但是功能100%是没有任何问题的。

JS对联广告代码效果

    A+
发布日期:2017年12月25日 20:14:34  所属分类:JavaScript
最后更新时间:2017-12-26 16:10:10
付杰
  • ¥ 298.0元
  • 市场价:398.0元
  • ¥ 818.0元
  • 市场价:1688.0元
  • ¥ 69.0元
  • 市场价:69.0元
  • ¥ 189.0元
  • 市场价:269.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  0   博主  0

  1. 头像 小小 5

    今天我参考博主这个文章,根据项目需求,我又升级了一下,代码如下:

    <script>
    //获取分辨率宽度
    var iScreenWidth = window.screen.width;
    if(iScreenWidth > 1000){
    	//右侧对联
        document.write("<DIV  style='position:fixed;float:right;right:0px;top:300px;'><a href='#' target='_blank'><img src='https://www.hsshoo.com/wp-content/uploads/2020/08/5963.jpg' width='200px' height='200px'></a><p style='text-align: center'>代购微信号:Win0_Sky</p></div>");
     }
     if(iScreenWidth < 1000){
    	//底部
        document.write("<DIV  style='position:fixed;bottom:0px;height:50px;width:100%;z-index:999'><p style='text-align: center;background:#3e80e6; color:#FFFFFF;line-height:50px;'>代购微信号:Win0_Sky</p></div>");
     }
     </script>