zoukankan      html  css  js  c++  java
  • 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>");
  • 相关阅读:
    springmvc上传下载
    在线剪切
    Spring入门
    登录验证后端添加过滤器
    SpringMVC入门
    ScriptManager 以及ScriptManagerProxy在母版中使用和Service属性的使用
    GridView中如何使用CommandField删除时,弹出确认框?
    C# 测量用指定的 Font 绘制的指定字符串。(指定字符串的像素长度)
    ASP.NET AJAX 简单地过一下每个控件(ScriptManager、ScriptManagerProxy、UpdatePanel、 UpdateProgress和Timer)
    XML结构和数据导入到SQL server
  • 原文地址:https://www.cnblogs.com/baidawei/p/4755428.html
Copyright © 2011-2022 走看看