zoukankan      html  css  js  c++  java
  • js高级程序设计BOM

    //取得页面视口大小
    //for others
    var pageWidth = window.innerWidth,
    pageHeight = window.innerHeight;
    //for IE
    if (typeof pageWidth != "number") {
    if (document.compatMode == "CSS1Compat") {
    // for standard compatMode
    pageWidth = document.documentElement.clientWidth;
    pageHeight = document.documentElement.clientHeight;
    } else {
    // else
    pageWidth = document.body.clientWidth;
    pageHeight = document.body.clientHeight;
    }
    }

    window.resizeTo(100, 100); //调整到100*100
    window.resizeBy(100, 50); //调整到200*150,基于上面

    //打开一个新窗口
    var wroxWin = window.open("http://www.baidu.com/", "wroxWindow", "height=400,width=400,top=10,left=10,resizable=yes");
    //调整大小
    wroxWin.resizeTo(500, 100);
    //移动位置
    wroxWin.moveTo(100, 100);
    //关闭新打开的窗口
    wroxWin.close();
    alert(wroxWin.closed); //true
    //原始窗口对象
    alert(wroxWin.opener == window); //true
    //将opener属性设置为null,即表示在单独的进程中运行新标签页
    wroxWin.opener = null;

    //弹出窗口屏蔽程序
    var blocked = false;
    try {
    //浏览器内置的屏蔽程序阻止的弹出窗口
    var wroxWin1 = window.open("http://www.baidu.com/", "_blank");
    if (wroxWin == null) {
    blocked = true;
    }
    } catch (ex) {
    //浏览器扩展或其他程序阻止的弹出窗口,会被抛出一个错误
    blocked = true;
    }
    if(blocked){
    alert("popup had been blocked");
    }

    /********** location对象 ***********/
    //查询location.search返回的字符串参数
    function getQueryStringArgs(){
    //取得查询字符串并去掉开头的问号
    var qs=(location.search.length>0?location.search.substring(1):"");
    //保存数据对象
    var args={};
    //取得每一项
    var items=qs.split("&");
    var item,name,value;
    //逐个将每一项添加到args对象中
    for(var i=0;i<items.length;i++){
    item=items[i].split("=");
    name=decodeURIComponent(item[0]);
    value=decodeURIComponent(item[1]);
    args[name]=value;
    }
    return args;
    }

    //在调用replace方法之后,用户不能回到前一个页面
    setTimeout(function(){
    location.replace("www.baidu.com/");
    },1000); //1s后执行

    location.reload(); //重新加载(有可能从缓存中加载)
    location.reload(true); //重新加载(从服务器重新加载)

    /************* navigation对象 ****************/
    //检测插件
    //for others
    function hasPlugin(name){
    name=name.toLowerCase();
    for(var i= 0,len=navigator.plugins.length;i<len;i++){
    if(navigator.plugins[i].name.toLowerCase().indexOf(name)>-1){
    return true;
    }
    }
    return false;
    }
    //检测flash
    console.log(hasPlugin("Flash"));
    //检测Quicktime
    console.log("QuickTime");
    //检测Java
    console.log("Java");

    //检测IE中的插件
    function hasIEPlugin(name){
    try {
    new ActiveXObject(name);
    return true;
    } catch(ex){
    return false;
    }
    }
    //检测flash
    console.log(hasIEPlugin("ShockwaveFlash.ShockwaveFalsh"));
    //检测QuickTime
    console.log("QuickTime.QuickTime");

    //检测所有浏览器中的flash
    function hasFlash(){
    var result=hasPlugin("Flash");
    if(!result){
    result=hasIEPlugin("ShockwaveFlash.ShockwaveFlash");
    }
    return result;
    }

    //检测所有浏览器中的QuickTime
    function hasQuickTime(){
    var result=hasPlugin("QuickTime");
    if(!result){
    result=hasIEPlugin("QuickTime.QuickTime");
    }
    return result;
    }

    //后退一页
    history.go(-1); //等于history.back();
    history.go(1); //前进一页,等于history.forward();
    history.go("wrox.com"); //跳转到最近的wrox.com

  • 相关阅读:
    安装Python 3.6 在Ubuntu 16.04 LTS 版本
    [leetcode]447. Number of Boomerangs
    【leetcode】443. String Compression
    第7课 课堂学习小问答
    第11章 进程间通信(4)_进程信号量
    第11章 进程间通信(3)_共享内存
    第11章 进程间通信(2)_消息队列
    第11章 进程间通信(1)_管道
    第10章 线程控制(5)_多线程下的fork
    第10章 线程控制(4)_多线程下的信号
  • 原文地址:https://www.cnblogs.com/webFrontDev/p/2753492.html
Copyright © 2011-2022 走看看