zoukankan      html  css  js  c++  java
  • js-浏览器DOM

    1.window尺寸

    适配所有浏览器的尺寸方案

    var w=window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;
    var h=window.innerHeight
    || document.documentElement.clientHeight
    || document.body.clientHeight;

    2.window打开关闭窗口

    window.open("index01.html","name","width = 300, height = 300,left = 200,top = 200");

    window.close();关闭自己

    3.计时器setInterval和clearInterval定时执行

    var mytime = setInterval(function(){
      getTime();
    },1000);
    function getTime(){
      var d = new Date();
      var t = d.toLocaleTimeString();
      document.getElementById("ptime").innerHTML = t;
    }
    function stopTime(){
      clearInterval(mytime);
    }

    4.计时器setTimeout延时执行

    var myVar;
    function myFunction()
    {
      myVar=setTimeout(function(){alert("Hello")},3000);自己调自己可以循环

    }

    function myStopFunction()

    {
      clearTimeout(myVar);
    }

    5.History

    history.back() - 与在浏览器点击后退按钮相同

    history.forward() - 与在浏览器中点击按钮向前相同

    history.go() - 跳到某个

    6.Location

    location.href 属性返回当前页面的 URL。

    location.hostname 返回 web 主机的域名

    location.pathname 返回当前页面的路径和文件名

    location.port 返回 web 主机的端口 (80 或 443)

    location.protocol 返回所使用的 web 协议(http:// 或 https://)

    location.assign() 方法加载新的文档。

    7.Screen

    screen.availWidth - 可用的屏幕宽度

    screen.availHeight - 可用的屏幕高度

    8.弹窗

    弹窗使用 反斜杠 + "n"( ) 来设置换行。

    ---警告框

    alert();

    ---确认框

    var r=confirm("按下按钮");

    if (r==true){x="你按下了"确定"按钮!";}

    else{x="你按下了"取消"按钮!";}

    ---提示框

    window.prompt("sometext","defaultvalue");

  • 相关阅读:
    设定cookie 获取cookie数据的转换
    cookie cookie的获取
    常见的请求方式 json字符串
    请求报文和响应报文
    http协议
    php分页查询 子查询
    MAC 地址为什么不需要全球唯一
    ceph分布式存储简介
    一文看懂为什么边缘计算是大势所趋
    真香!Windows 可直接运行 Linux 了
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5981747.html
Copyright © 2011-2022 走看看