Home >  > 关闭网页弹出“设为主页”和“添加到收藏夹”提示代码

关闭网页弹出“设为主页”和“添加到收藏夹”提示代码

1

收藏了两个对于站长来说非常实用的代码,效果是打开或关闭网页弹出“设为主页”和“添加到收藏夹”提示,并且记录cookies,24小时只弹出一次。本人已经在IE下测试通过,如果感觉网页代码很臃肿的话,可以用"html转换成js"工具进行转换,调用JS即可。

提示:通常我们进入别人网站会用这样的提示,其实并不是打开网站就立即提示,而是点击网站上任意链接才会弹出提示,此代码也不例外,希望可以带给你帮助。

记录cookies实现关闭网页弹出“设为主页”代码

[sourcecode language="html"]
<script>
function getCookie(name) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ';', len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 1; //此 cookie 将被保存 1 天
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function setpage(aa,str){
//注意,只对IE有效,FF需要修改浏览器设置
aa.style.behavior="url(#default#homepage)";
var bb=getCookie("username"); //读取cookies
if (bb!='easyplay8er')
{
aa.setHomePage(str);
SetCookie("username","easyplay8er");
}
}
</script>
<body onclick="setpage(this,'http://www.bestchao.com/');">
</body>
[/sourcecode]

记录cookies实现关闭网页弹出“加入收藏”代码

[sourcecode language="html"]
<script language="javascript" type="text/javascript">
function bookmark()
{
if(readCookie("bookmark")!="yes")
{
saveCookie("bookmark","yes",1);
window.external.AddFavorite('http://www.bestchao.com/', 'BestChao's Blog');
}
}

function saveCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000))
var expires = "; expires="+date.toGMTString()
}
else expires = ""
document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
var nameEQ = name + "="
var ca = document.cookie.split(';')
for(var i=0;i<ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length)
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
}
return null
}
</script>
<body onUnload="bookmark()">
</body>
[/sourcecode]

相关推荐

本文暂无标签
Comment (1)
Trackback (0)
  1. 麦田守望者 unknowunknow 沙发 2009/06/09 17:11

    我遇到这种提示的网站,都会诅咒它!
    [reply=BestChao,2009-06-09 06:19 PM]呵呵,幸好我没有加此代码。[/reply]

  • 还没有Trackback

发表评论

You must be logged in to post a comment.