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();
                }
            }
  • 相关阅读:
    记录我的第一次电话面试
    Spring整合Mybatis出现Access denied for user 'Think'@'localhost' (using password: YES)
    Lombok基本使用
    log4j整理
    mybatis常用的配置解析
    Java实现邮件发送
    Java获取UUID
    Java实现文件下载
    Java实现文件上传
    Java跳出多层for循环的4种方式
  • 原文地址:https://www.cnblogs.com/wcx-20151115-hzz/p/14985456.html
Copyright © 2011-2022 走看看