• 24、Javascript BOM


    BOM(Browser Object Model)浏览器对象模型,一组浏览器提供的API。

    window对象

    window对象表示当前浏览器的窗口,是Javascript的顶级对象,所有创建的对象、函数、变量都是window对象的成员。

    通常,我们使用window对象的属性和方法时,都将省略window关键字,window对象是一个全局的对象。

    如:window.onload , window.document , window.变量名 , window.标签ID

    confirm()方法

    window.onload=function()
    {
        //confirm方法
        //以下都可以 可以省略window
        //window.document.getElementById("btn").onclick=function(){}
        //window.btn.onclick=function(){}
        btn.onclick=function(){
            if(confirm("你确定这样做吗"))
            {
                alert("选择了是");
            }
        }
    }

    Location对象

    location对象用来获取当前页面的地址(URL),并可以将浏览器重定向到新地址。

    document.write("URL:" + location.href + "<br>");
    document.write("域名:" + location.host + "<br>");
    document.write("主域名(不带www的域名):" + location.hostname + "<br>");
    document.write("路径:" + location.pathname + "<br>");
    document.write("协议:" + location.protocol);

    常用的就是href,host,reload();

    <button id="baidu" onclick="location.href='http://www.baidu.com/'">去百度</button>
    <button id="reload" onclick="location.reload()">刷新</button>

    History对象

    history对象包含浏览器的历史信息。

    用户可以通过浏览器前进或者后退访问浏览过的页面。Javascript的history对象记录了用户曾经浏览过的页面,可以实现类似功能。

    <button onclick="history.forward();">前进</button>
    <button onclick="history.back();">后退</button>

    forward前进一页,back后退一页,还有个go()方法,go(1)前进一页,go(-1)后退一页,go(0)刷新页面。

    Navigator对象

    navigator对象通常用于获取浏览器和操作系统的信息。

    document.write("浏览器名称:"+navigator.appName + "<br>");
    document.write("平台和版本:"+navigator.appVersion + "<br>");
    document.write("操作系统:"+navigator.platform + "<br>");
    document.write("userAgent:"+navigator.userAgent + "<br>");

    Screen对象

    screen对象主要用来获取用户屏幕的信息。

    document.write("屏幕信息:<br>");
    document.write("分辨率:"+screen.width + " * " + screen.height +"<br>");
    document.write("可用区域:"+screen.availWidth + " *" + screen.availHeight + "<br>");
  • 相关阅读:
    usb mtp激活流程【转】
    [RK3288][Android6.0] USB OTG模式及切换【转】
    简单实用的磁带转MP3方法图解
    使用log4j的邮件功能
    hive从查询中获取数据插入到表或动态分区
    map和reduce 个数的设定 (Hive优化)经典
    Mysql ERROR 145 (HY000)
    Mysql计算时间差
    小米刷机教程和GAE for android
    Hbase 使用方法
  • 原文地址:https://www.cnblogs.com/baidawei/p/4755428.html
Copyright © 2020-2023  润新知