下载站常用的点击下载地址提示设hao123为首页的js代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

下载站常用的点击下载地址提示设hao123为首页的js代码

  2020-05-13 我要评论
一般情况我们在不修改原来页面布局的情况下,如果原来的点击区域有id的话比较好,要不要修改下,这样比较好控制,否则没个下载地址的a标签里面都要加onclick事件了。

效果图:



核心代码:

复制代码 代码如下:

<script>
function GetCookie (name)
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
function SetCookie (name, value)
{
  var second = 15*60; //多少秒
  var exp  = new Date();
  exp.setTime(exp.getTime() + second*1000);

  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((exp == null) ? "" : ("; expires=" + exp.toGMTString())) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function $(id){return document.getElementById(id);}
$("downAddress").onclick = function () { address_click(); }
/https://img.qb5200.com/download-x/downAddress就是下载区域所在的id,如果是class的需要修改下,如果你使用的jquery可以根据需要设置下就可以了
var isTrue = false;
var userHome = GetCookie("isHome");
function address_click()
{
    if(userHome == null || userHome == "")
        {if(!isTrue)
        {
          document.body.style.behavior="url(#default#homepage)";
          document.body.setHomePage('http://www.hao123.com/?tn=92961071_hao_pg');
          SetCookie("isHome","yes");
          userHome = "yes"
        }
    }
    return true;
}
</script>



下面附上一个更简单的点击设置首页的代码,跟上面的没有关系,下面的事通过单个链接的onclick触发的,大家可以根据需要修改


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们