首次点击自动弹出百度搜索代码教程

2018-06-06 15:19:28 浏览数 (1)

这个弹窗方式是我模仿城通网盘的弹窗广告做的,使用js取、设cookie来判断是否弹窗

js代码如下:

代码语言:javascript复制
<script>
if (getCookie("baidu_tc")!="1"){
	var array = new Array('关键词1','杨小杰博客','小杰');
	document.write('<a href="http://www.baidu.com/s?ie=UTF-8&amp;wd='   encodeURIComponent(array[Math.floor(Math.random()*(array.length))])   '" target="_blank" style="position: absolute; z-index: 9999999999; opacity: 0.1;top: 0px; left: 0px; width: 100%; height: ' document.body.offsetHeight 'px; background-color: rgb(255, 255, 255);" id="baidu_tc" onclick="baidu_tc();"></a>');
	function baidu_tc(){
		document.getElementById("baidu_tc").style.display="none";
		setCookie("baidu_tc","1");
	}
}

function setCookie(cname,cvalue){
  document.cookie = cname   "="   cvalue   "; path=/";
}

function getCookie(cname){
  var name = cname   "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i  ) {
    var c = ca[i].trim();
    if (c.indexOf(name)==0){
		return c.substring(name.length,c.length);
	}
  }
  return "";
}
</script>

修改关键词后添加到模版尾部即可

原文地址:https://www.9ifz.cc/qtym/1667.html

0 人点赞