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

<article class="article-content">
<p>
此方法影响用户体验,慎用!!
</p>
<p>
增加下面的JS代码可实现用户点击页面处弹出百度搜索进行刷展现,搜索
</p>
<p>
这个弹窗方式是久爱辅助模仿城通网盘的弹窗广告做的,使用js取、设cookie来判断是否弹窗
</p>
<p>
js代码如下:
</p>
<pre class="prettyprint lang-js linenums prettyprinted"><ol class="linenums"><li class="L0"><span class="pun">&lt;</span><span class="pln">script</span><span class="pun">&gt;</span></li><li class="L1"><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">getCookie</span><span class="pun">(</span><span class="str">"baidu_tc"</span><span class="pun">)!=</span><span class="str">"1"</span><span class="pun">){</span></li><li class="L2"><span class="pln"> </span><span class="kwd">var</span><span class="pln"> array </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Array</span><span class="pun">(</span><span class="str">'AE博客'</span><span class="pun">,</span><span class="str">'墨渊博客'</span><span class="pun">,</span><span class="str">'AE墨渊'</span><span class="pun">);</span></li><li class="L3"><span class="pln"> document</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="str">'&lt;a href="http://www.baidu.com/s?ie=UTF-8&amp;wd='</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> encodeURIComponent</span><span class="pun">(</span><span class="pln">array</span><span class="pun">[</span><span class="typ">Math</span><span class="pun">.</span><span class="pln">floor</span><span class="pun">(</span><span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()*(</span><span class="pln">array</span><span class="pun">.</span><span class="pln">length</span><span class="pun">))])</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">'" target="_blank" style="position: absolute; z-index: 9999999999; opacity: 0.1;top: 0px; left: 0px; width: 100%; height: '</span><span class="pun">+</span><span class="pln">document</span><span class="pun">.</span><span class="pln">body</span><span class="pun">.</span><span class="pln">offsetHeight</span><span class="pun">+</span><span class="str">'px; background-color: rgb(255, 255, 255);" id="baidu_tc" onclick="baidu_tc();"&gt;&lt;/a&gt;'</span><span class="pun">);</span></li><li class="L4"><span class="pln"> </span><span class="kwd">function</span><span class="pln"> baidu_tc</span><span class="pun">(){</span></li><li class="L5"><span class="pln"> document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"baidu_tc"</span><span class="pun">).</span><span class="pln">style</span><span class="pun">.</span><span class="pln">display</span><span class="pun">=</span><span class="str">"none"</span><span class="pun">;</span></li><li class="L6"><span class="pln"> setCookie</span><span class="pun">(</span><span class="str">"baidu_tc"</span><span class="pun">,</span><span class="str">"1"</span><span class="pun">);</span></li><li class="L7"><span class="pln"> </span><span class="pun">}</span></li><li class="L8"><span class="pun">}</span></li><li class="L9"><span class="pln">&nbsp;</span></li><li class="L0"><span class="kwd">function</span><span class="pln"> setCookie</span><span class="pun">(</span><span class="pln">cname</span><span class="pun">,</span><span class="pln">cvalue</span><span class="pun">){</span></li><li class="L1"><span class="pln">  document</span><span class="pun">.</span><span class="pln">cookie </span><span class="pun">=</span><span class="pln"> cname </span><span class="pun">+</span><span class="pln"> </span><span class="str">"="</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> cvalue </span><span class="pun">+</span><span class="pln"> </span><span class="str">"; path=/"</span><span class="pun">;</span></li><li class="L2"><span class="pun">}</span></li><li class="L3"><span class="pln">&nbsp;</span></li><li class="L4"><span class="kwd">function</span><span class="pln"> getCookie</span><span class="pun">(</span><span class="pln">cname</span><span class="pun">){</span></li><li class="L5"><span class="pln">  </span><span class="kwd">var</span><span class="pln"> name </span><span class="pun">=</span><span class="pln"> cname </span><span class="pun">+</span><span class="pln"> </span><span class="str">"="</span><span class="pun">;</span></li><li class="L6"><span class="pln">  </span><span class="kwd">var</span><span class="pln"> ca </span><span class="pun">=</span><span class="pln"> document</span><span class="pun">.</span><span class="pln">cookie</span><span class="pun">.</span><span class="pln">split</span><span class="pun">(</span><span class="str">';'</span><span class="pun">);</span></li><li class="L7"><span class="pln">  </span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">var</span><span class="pln"> i</span><span class="pun">=</span><span class="lit">0</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">&lt;</span><span class="pln">ca</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span><span class="pln"> i</span><span class="pun">++)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L8"><span class="pln">    </span><span class="kwd">var</span><span class="pln"> c </span><span class="pun">=</span><span class="pln"> ca</span><span class="pun">[</span><span class="pln">i</span><span class="pun">].</span><span class="pln">trim</span><span class="pun">();</span></li><li class="L9"><span class="pln">    </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">c</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="pln">name</span><span class="pun">)==</span><span class="lit">0</span><span class="pun">){</span></li><li class="L0"><span class="pln"> </span><span class="kwd">return</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">substring</span><span class="pun">(</span><span class="pln">name</span><span class="pun">.</span><span class="pln">length</span><span class="pun">,</span><span class="pln">c</span><span class="pun">.</span><span class="pln">length</span><span class="pun">);</span></li><li class="L1"><span class="pln"> </span><span class="pun">}</span></li><li class="L2"><span class="pln">  </span><span class="pun">}</span></li><li class="L3"><span class="pln">  </span><span class="kwd">return</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span></li><li class="L4"><span class="pun">}</span></li><li class="L5"><span class="pun">&lt;/</span><span class="pln">script</span><span class="pun">&gt;</span></li></ol></pre>
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(2)

【暴力项目】无需引流,日赚500+,当天收款,人人可操作

1、首先这个项目当然是可以长期做的,不是做几天就死的短期项目!
2、项目操作简单,一学就会,人人可以操作!
3、操作本项目需要投资100元以下,什么0投资也能赚钱的你相信吗?
4、项目是大众项目,上万人同时操作无半点影响!
5、完全的正规合法,阳光项目,并且是真正的长期可一直操作的项目!
6、我不是雷锋,你赚钱了给我分20%的利润,不会分钱是不会永久带你的。

同意以上观点:
加微信wbaa1993 (验证码a010) 会马上通过好友请求
4周前 (2018-03-30) 回复
感谢分享,很实用的代码
耐火砖 2个月前 (2018-02-27) 回复