• 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();
                }
            }
  • 相关阅读:
    linux c++爬虫(一)
    计算进程消费cpu和内存
    ZooKeeper server &&client
    ZooKeeper 数据模型
    转载 分布式协调技术 分布式锁
    转载 ~shell简介
    增删改查时要注意的几个地方
    搜索时,大小写问题
    ajax的一些实用技巧
    向redis插入数据时,返回值问题
  • 原文地址:https://www.cnblogs.com/wcx-20151115-hzz/p/14985456.html
Copyright © 2020-2023  润新知