核心代碼:
復制代碼 代碼如下:
<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(); }
//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需刷新才能執行]