先在head中引入
<script src="http://www.discuz.net/static/js/common.js?czD" type="text/javascript"></script>
<script type="text/javascript">
function set_homepage($url){ // 设置首页
if (document.all){
document.body.style.behavior = 'url(#default#homepage)'
document.body.setHomePage($url)
}else if (window.sidebar){
if (window.netscape){
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
}catch (e) {
alert("该 *** 作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true")
}
}
var prefs = Components.classes['@mozilla.org/preferences-service1'].getService(Components.interfaces.nsIPrefBranch)
prefs.setCharPref('browser.startup.homepage', '$url')
}
}
</script>
然后在你需要的地方插入
<a href="javascript:" onclick="set_homepage('你的网址')">设为首页</a><a href="http://www.discuz.net/" onclick="addFavorite('你的网址', '网站名称')return false">收藏本站</a>
直接将此代码写入页面的总代吗即可,代码如下:记录cookies实现退出网页时d出“加入收藏”的代码:
<script language="java script" type="text/java script">
function bookmark()
{
if(readCookie("bookmark")!="yes")
{
saveCookie("bookmark","yes",1)
window.external.AddFavorite('这里输入需要收藏的网站网址, '关键词)
}
}
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=0i<ca.lengthi++) {
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>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)