一般情况我们在不修改原来页面布局的情况下,如果原来的点击区域有id的话比较好,要不要修改下,这样比较好控制,否则没个下载地址的a标签里面都要加onclick事件了。
效果图:
核心代码:
<script><BR>function GetCookie (name)<BR>{<BR> var arg = name + "=";<BR> var alen = arg.length;<BR> var clen = document.cookie.length;<BR> var i = 0;<BR> while (i < clen) {<BR> var j = i + alen;<BR> if (document.cookie.substring(i, j) == arg)<BR> return getCookieVal (j);<BR> i = document.cookie.indexOf(" ", i) + 1;<BR> if (i == 0) break; <BR> }<BR> return null;<BR>}<BR>function SetCookie (name, value)<BR>{<BR> var second = 15*60; //多少秒<BR> var exp = new Date();<BR> exp.setTime(exp.getTime() + second*1000);
<P> var argv = SetCookie.arguments;<BR> var argc = SetCookie.arguments.length;<BR> var expires = (argc > 2) ? argv[2] : null;<BR> var path = (argc > 3) ? argv[3] : null;<BR> var domain = (argc > 4) ? argv[4] : null;<BR> var secure = (argc > 5) ? argv[5] : false;<BR> document.cookie = name + "=" + escape (value) +<BR> ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +<BR> ((path == null) ? "" : ("; path=" + path)) +<BR> ((exp == null) ? "" : ("; expires=" + exp.toGMTString())) +<BR> ((domain == null) ? "" : ("; domain=" + domain)) +<BR> ((secure == true) ? "; secure" : "");<BR>}
<P>function $(id){return document.getElementById(id);}<BR>$("downAddress").onclick = function () { address_click(); }<BR>//downAddress就是下载区域所在的id,如果是class的需要修改下,如果你使用的jquery可以根据需要设置下就可以了<BR>var isTrue = false;<BR>var userHome = GetCookie("isHome");<BR>function address_click()<BR>{<BR> if(userHome == null || userHome == "")<BR> {if(!isTrue)<BR> {<BR> document.body.style.behavior="url(#default#homepage)";<BR> document.body.setHomePage('http://www.hao123.com/?tn=92961071_hao_pg'); <BR> SetCookie("isHome","yes");<BR> userHome = "yes"<BR> }<BR> }<BR> return true;<BR>} <BR></script>
下面附上一个更简单的点击设置首页的代码,跟上面的没有关系,下面的事通过单个链接的onclick触发的,大家可以根据需要修改