• JavaScript高级程序设计18.pdf


    系统对话框

    alert()、confirm()和prompt()调用系统对话框向用户显示消息,显示对话框的时候代码会停止执行,关闭后继续执行

    alert()警告提示框

    confirm()点击确认返回true,退出或关闭返回false

    prompt()在第二个的基础上多一个文本输入域,有2个参数,第二个参数是文本输入域默认值

    prompt("What's your name ?","Michael"),点击确认返回文本输入域的值,其他情况返回null

    某些浏览器对多个对话框实现了禁用复选框,如勾选了禁用复选框,除非刷新,否则屏蔽后续对话框

    location对象

    location对象提供了当前加载窗口中文档有关的信息,还提供了一些导航功能,location既是window的属性也是document对象的属性

    location对象的属性将URL解析为独立的片段,开发人员可以访问不同的属性访问这些片段

    修改这些属性可以更改浏览器位置,这些修改会保存在浏览器历史记录中,可以使用

    location.replace("http://www.baidu.com")//重定向到新网址,且不能返回前一个页面

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

    location.reload(true);  //从服务器重新加载

    查询字符串参数

    function getQueryStringArgs(){

        //取得查询字符串并去掉开头的问号

        var qs=(location.search.length>0 ? location.search.substring(1) : " "),

        args={},

        items=qs.length ? qs.split("&"):[],

        item=null,

        name=null,

        value=null,

        i=0,

        len=items.length;

        for(i=0,i<len;i++){

          item=items[i].split("=")

          name=decodeURLComponent(item[0]);

          value=decodeURLComponent(item[1]);

          if(name.lenth){

            args[name]=value;

            }

          }

        return args;

        }

    navigator对象

    navigator对象用于检测显示网页的浏览器类型

    检测插件

    非IE浏览器可以使用plugins数组来达到检测插件的目的,该数组的每一项都包含下列属性

    name:插件的名称

    description:插件的描述

    filename:插件的文件名
    length:插件所处理的MIME类型数量

    //在IE中无效

    function hasPlugin(name){

        name=name.toLowerCase();

        for(var i=0;i<navigator.plugins.length;i++){

          if(navigator.plugins[i].name.toLowerCase().indexOf(name)>-1){

            return true;

            }

          }

        return false;

        }

    alert(hasPlugin("Flash"));

    检测IE中的插件唯一方式是使用专有的ActiveXObject类型,并尝试创建一个特定插件的实例。IE是以COM对象的方式实现插件的,而COM对象使用唯一标识符来标识,Flash的标识符是ShockwaveFlash.ShockwaveFlash。

    //检测IE中的插件

    function hasIEPlugin(name){

        try{

          new ActiveXObject(name);

          return true;

          }

        catch(ex){

          return false;

          }

        }

    //检测Flash

    alert(hasIEPlugin("ShockwaveFlash.ShockwaveFlash"));

    //检测QuickTime

    alert(hasIEPlugin("QuickTime.QuickTime"));

    //检测所有浏览器中的Flash

    function hasFlash(){

      var result=hasPlugin("Flash");

      if(!result){

        result=hasIEPlugin("ShockwaveFlash.ShockwaveFlash");

        }

       return result; 

     }

  • 相关阅读:
    vbs习题
    spotlight监控工具使用
    vue 不同路由同一个组件 缓存问题
    iphone手机上3D动画transform:rotateY闪现一下或者不显示
    vue 单独引用sass文件
    cnpm安装 npm安装node-sass报错
    webpack 打包css时提示Unexpected character '@'
    window下npm启动报错This is probably not a problem with npm. There is likely additional logging output above.
    HBuilder 配置android模拟器
    windows 切换git远程仓库地址后 git push 提示Authentication failed
  • 原文地址:https://www.cnblogs.com/sdgjytu/p/3738014.html
Copyright © 2020-2023  润新知