例子,设置为首页与加入收藏。
代码:
//设置首页
function setHomePage(obj) {
var aUrls = document.URL.split("/");
var vDomainName = "http://" + aUrls[2] + "/";
try {//IE
obj.style.behavior = "url(#default#homepage)";
obj.setHomePage(vDomainName);
} catch (e) {//other
if (window.netscape) {//Firefox
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("此操作被浏览器拒绝!n请在浏览器地址栏输入“about:config”并回车n然后将[signed.applets.codebase_principal_support]设置为'true'");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vDomainName);
}
}
if (window.netscape) alert("设置首页成功!");
return false; //阻止a标签继续执行
}
//加入收藏函数
function addFavorite(obj) {
var aUrls = document.URL.split("/");
var vDomainName = "http://" + aUrls[2] + "/";
var description = obj.title;
try {//IE
window.external.AddFavorite(vDomainName, description);
} catch (e) {//Firefox
window.sidebar.addPanel(description, vDomainName, "");
}
return false; //阻止a标签继续执行
}
function funBackTop() {
var elem = $('.backtop'), h = window.screen.height, time = null, srctop = 0;
this.init = function () {
elem.bind('click', function () {
$('#container').scrollTop(0);
})
time = setInterval(function () {
srctop = $('#container').scrollTop();
if (srctop > h) {
elem.show();
}
else {
elem.hide();
}
}, 500)
}
}