当前位置: 首页 > news >正文

JavaScript 浏览器对象(三)

一、Location对象

    1.location对象:window.location对象用于获取当前页面的地址(URL),并把浏览器重定向到新的页面。

    2.location对象的属性:

      location.hostname返回web主机的域名

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

      location.port返回web主机的端口

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
     <head>
         <meta charset= "UTF-8" >
         <title></title>
     </head>
     <body>
         <button id= "btn"  onclick= "getLoc()" >按钮</button>
         <p id= "ptime" ></p>
         <script>
             function  getLoc(){
//              document.getElementById("ptime").innerHTML = window.location.hostname;
//              document.getElementById("ptime").innerHTML = window.location.pathname;
//              document.getElementById("ptime").innerHTML = window.location.port;
//              document.getElementById("ptime").innerHTML = window.location.href;
                 location.assign( "http://www.baidu.com" );
             }
         </script>
     </body>
</html>


二、Screen对象

    1.Screen对象:

      window.screen对象包含有关用户屏幕的信息

    2.属性:

      screen.availWidth-可用的屏幕宽度

      screen.availHeight-可用的屏幕高度

      screen.Height-屏幕高度

      screen.Width-屏幕宽度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
     <head>
         <meta charset= "UTF-8" >
         <title></title>
     </head>
     <body>
         <button id= "btn"  onclick= "getLoc()" >按钮</button>
         <p id= "ptime" ></p>
         <script>
             document.write( "可用高度:" +screen.availHeight+ ",可用宽度" +screen.availWidth);
             document.write( "高度:" +screen.height+ ",宽度" +screen.width);
         </script>
     </body>
</html>

      


本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1794366



相关文章:

  • 命令行程序测试自动化
  • Linux命令行翻译工具
  • 保障邮件安全
  • Linux系统_Centos7下安装Nginx
  • 源码安装Apache服务器遇到的问题及解决方法
  • 优秀互联网高级测试工程师应该具备的能力
  • raid5实现原理
  • Go 可变参数和切片
  • Tomcat7 catalina.out 日志分割
  • storm drpc实例
  • 监控CPU(一)
  • RIP
  • Lintcode104 Merge k Sorted Lists solution 题解
  • jQuery基础一
  • heartbeat主配置文件
  • 0基础学习移动端适配
  • 2017-08-04 前端日报
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
  • Java超时控制的实现
  • Js实现点击查看全文(类似今日头条、知乎日报效果)
  • MYSQL 的 IF 函数
  • python docx文档转html页面
  • React系列之 Redux 架构模式
  • React中的“虫洞”——Context
  • Spring Boot快速入门(一):Hello Spring Boot
  • windows下mongoDB的环境配置
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 记录一下第一次使用npm
  • 聊聊hikari连接池的leakDetectionThreshold
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 使用SAX解析XML
  • 事件委托的小应用
  • 突破自己的技术思维
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • 带你开发类似Pokemon Go的AR游戏
  • ​configparser --- 配置文件解析器​
  • #QT(串口助手-界面)
  • (16)Reactor的测试——响应式Spring的道法术器
  • (4)事件处理——(7)简单事件(Simple events)
  • (js)循环条件满足时终止循环
  • (过滤器)Filter和(监听器)listener
  • (理论篇)httpmoudle和httphandler一览
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (转)ORM
  • (转)shell调试方法
  • .net MVC中使用angularJs刷新页面数据列表
  • .net 发送邮件
  • .NET开源全面方便的第三方登录组件集合 - MrHuo.OAuth
  • .Net下使用 Geb.Video.FFMPEG 操作视频文件
  • .sh 的运行
  • @cacheable 是否缓存成功_让我们来学习学习SpringCache分布式缓存,为什么用?
  • @RestController注解的使用
  • @软考考生,这份软考高分攻略你须知道