zoukankan      html  css  js  c++  java
  • js 实现 收藏地址,设为浏览器首页,关闭浏览器

    将某页面设为浏览器的首页:

    function setHome(obj) {
        var url = window.location.href
        try {
            obj.style.behavior = 'url(#default#homepage)';
            obj.setHomePage(url);
        } catch (e) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } catch (e) {
                    alert(
                        "抱歉,此操作被浏览器拒绝!
    
    请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
                }
            } else {
                alert("抱歉,您所使用的浏览器无法完成此操作。
    
    您需要手动将【" + url + "】设置为首页。");
            }
        }
    }
     
    将某地址收藏:
    function addFavor(title) {
        var url = window.location.href
        if (window.sidebar) return true;
        try{
            window.external.addFavorite(url, title);
        }catch(e){
            alert("抱歉,您所使用的浏览器无法完成此操作。
    
    加入收藏失败,请使用Ctrl+D进行添加");
        }
        return false;
    }

    关闭浏览器

    function CloseWebPage() {
                console.log(navigator.userAgent.indexOf("Chrome"))
                if (navigator.userAgent.indexOf("MSIE") > 0) {
    
                    if (navigator.userAgent.indexOf("MSIE 6.0") > 0) { //适用于ie6不带提示关闭窗口
    
                        window.opener = null;
    
                        window.close();
    
                    } else {
                        window.open('', '_top'); //ie7之后不提示关闭窗口
    
                        window.top.close();
    
                    }
    
                } else if (navigator.userAgent.indexOf("Firefox") > 0) { //Firefox不提示关闭窗口
    
                    window.location.href = 'about:blank ';
    
                } else {
                    window.opener = null;
                    window.open(' ', '_self', ' '); //其他浏览器
                    window.close();
                }
            }
  • 相关阅读:
    字典序算法
    C语言中strcpy,strcmp,strlen,strcat函数原型
    堆和栈概念整理
    distribution counting—a sorting method from aocp
    矩阵访问测试
    一个很大的数组,如何高效的把零都移到前面
    poj1083
    AXD+HJTAG环境搭建总结
    软件断点和硬件断点的区别和数量限制
    Ubuntu下用as汇编器编写hello.S文件
  • 原文地址:https://www.cnblogs.com/wcx-20151115-hzz/p/14985456.html
Copyright © 2011-2022 走看看