zoukankan      html  css  js  c++  java
  • canvas_28 window API

    windowFunc() {
                    // window作为全局变量,代表了脚本正在运行的窗口,暴露给 Javascript 代码。
                    let uA = navigator.userAgent.toLowerCase();
    
                    // 01. 判断是移动端还是PC端
                    var mobileOrPc = () => {
                        var ipad = uA.match(/ipad/i) == "ipad";
                        var iphone = uA.match(/iphone os/i) == "iphone os";
                        var midp = uA.match(/midp/i) == "midp";
                        var uc7 = uA.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
                        var uc = uA.match(/ucweb/i) == "ucweb";
                        var android = uA.match(/android/i) == "android";
                        var windowsce = uA.match(/windows ce/i) == "windows ce";
                        var windowsmd = uA.match(/windows mobile/i) == "windows mobile";
                        if (!(ipad || iphone || midp || uc7 || uc || android || windowsce || windowsmd)) {
                            this.msg = "PC端";
                        } else {
                            this.msg = "移动端";
                        }
                        console.log(uA);
                    };
    
                    // 02. 控制当前窗口的关闭
                    var isClosed = () => {
                        if (!window.closed) {
                            window.close();
                        }
                    };
    
                    // 03. 加密,随机数填充
                    var isCrypto = () => {
                        var array = new Uint32Array(10);
                        console.log(array);
                        window.crypto.getRandomValues(array);
                        console.log(array);
                    }
    
                    // 04. 本地存储 与 清除 用法同 sessionStorage
                    var setLocalStorage = () => {
                        var myStorage = window.localStorage;
                        myStorage.setItem("name", "zk");
                        console.log(myStorage.getItem("name"));
                        myStorage.removeItem("name");
                        console.log(myStorage.getItem("name"));
                        myStorage.clear();
                    }
    
                    // 05. 滚动条位置
                    var testScroll = () => {
                        // 为了跨浏览器兼容性,请使用 window.pageXOffset 代替 window.scrollX
                        if (window.scrollY > 400) {
                            window.scroll(0, 0);
                        }
                    }
    
                    testScroll
    
                    /*
                    其他 
                    
                    设备的物理像素分辨率与 CSS 像素分辨率的比率
                    var scale = window.devicePixelRatio;
                    
                    window.history // windows 页面历史
                    window.history.back(); // 返回上一页
                    window.history.go(-1); // 返回上一页
                    
                    window.innerHeight, window.innerWidth // 浏览器窗口的视口的宽高
                    window.outerHeight, window.outerWidth // 整个浏览器窗口的宽高
                    
                    console.log(window.location); // 当前页面链接
                    window.location = "http://www.mozilla.org"; // 当前页面打开URL
                    window.location.reload(true); // 强制从服务器重新加载当前页面
                    
                    window.name // 窗口名字
                    window.screen // 返回当前window的screen对象
                    
                    window.scrollbars.visible // 是否有滚动条
                    
                    
                    方法*********************************************************
                    window.alert("123"); // 弹出警告
                    
                    if (window.confirm("Do you really want to leave?")) // 弹出确认
                    
                    window.focus() // 将当前窗口放到最前
                    
                    window.minimize // 窗口最小化
                    
                    window.moveBy(100, 500); // 窗口移动了 xx xx
                    window.moveTo(100, 500); // 窗口移动到 xx xx
                    
                    window.open("http://www.baidu.com/", "BAIDU");
                    
                    window.print("文档1"); // 打印
                    
                    result = window.prompt("你喜欢什么", "默认值"); // 输入框
                    
                    window.requestAnimationFrame(func) //  告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画
                    
                    window.resizeBy(200, 200); window.resizeTo(100, 100) // 动态调整窗口的大小
                    
                    window.scroll(0, 500,); // 滚动到多少,功能与 window.scrollTo() 一样, 用法同下 
                    window.scrollBy({  // 支持参数:smooth (平滑滚动),instant (瞬间滚动),默认值 auto,效果等同于 instant
                      top: 100,
                      left: 100,
                      behavior: "smooth"
                    });
                    
                    window.stop(); // 停止加载
                    
                    */
                },
  • 相关阅读:
    201671010461张仲桃 实验三
    通读《构建之法》之后的问题
    201671010402-陈靖 实验十四 团队项目评审&课程学习总结
    201671010402-陈靖 实验四附加实验
    201671010402-陈靖——英文文本统计分析》结对项目报告
    201671010402 词频统计软件项目报告
    201671010402-陈靖 实验三 作业互评与改进
    读《现代软件工程——构建之法》所遇到的问题
    201671010403 陈倩倩 实验十四 团队项目评审&课程学习总结
    201671010403 陈倩倩 实验四附加实验
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15304055.html
Copyright © 2011-2022 走看看