加入收藏夹、打印、设置首页

加入收藏夹:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function addFav(){
if(document.all){
window.external.addFavorite('http://127.0.0.1/111111/video.html','XXX');
console.log( 'fvgdsfrg');
}else if(window.sidebar){
window.sidebar.addPanel('XXX', 'http://127.0.0.1/111111/video.html','');
}
}

</script>
<a href="http://127.0.0.1/111111/video.html" title="XXXX" rel="sidebar" onclick="addFav();">加入收藏</a></div>
<div style="border: 2px solid red;width: 80px;" onclick="addBookmark('dfsafasdfsa','http://127.0.0.1/111111/video.html')">加入收藏</div>
</body>
<script type="text/javascript">
function addBookmark(title, url) {

if (window.sidebar) {
window.sidebar.addPanel(title, url, "");
}
else if (document.all) {
window.external.AddFavorite(url, title);
}
else if (window.opera && window.print) {
window.alert('dfsa');
return true;
}

}
</script>
</html>

打印:

<script>
    function printpage() {    window.print()    }
</script>
<input type="button" value="Print this page" onclick="printpage()">

设置首页:

 function SetHome(obj, vrl) {
        try {
            obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
            NavClickStat(1);
        }
        catch (e) {
            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-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', vrl);
            }
        }
    }

 

posted @ 2016-01-05 11:55  镜子-正衣冠-知得失  阅读(310)  评论(0编辑  收藏  举报