美文网首页
javascript-History、Location、Scre

javascript-History、Location、Scre

作者: ssttIsme | 来源:发表于2020-01-01 20:30 被阅读0次

javascript-History、Location、Screen、Navigator对象

一、history对象

包含浏览器访问过的url
1.属性 length返回浏览器历史记录的数量
2.方法
back() 后退
forward()前进
go(数字)如果参数是正数,那么就是前进相应的数目,如果是负数那么反之,如果是.那么就是刷新

<button onclick="forward()">前进</button>
<script>
    function forward() {
        history.forward();
    }
</script>
<script>
    function back() {
        history.back();
    }
    function refresh() {
        history.go(0);
    }
</script>

二、location对象 包含当前url的相关信息

1.属性
href设置或返回完整的url

document.write(location.href); 
 location.href="history1.html";

search返回url?后面的查询部分

 document.write(location.search);

assign()加载新的文档(有历史记录)

location.assign("history1.html");

reload(boolean)重新加载文档,当参数是true的时候,任何时候都会重新加载。当参数是false的时候,只有在
文档改变的时候才会加载,否则直接读取内存当中的。

<button onclick="refresh()">刷新</button>
<script>
    function refresh() {
        location.reload();
    }
</script>

replace()用新的文档代替当前的文档(没有历史记录)

  location.replace("history2.html");

三、screen对象 记录了客户端显示屏的信息

属性:
availHeight 返回显示屏幕的高度(除windows任务栏之外)。
aviailWidth 返回显示屏幕的宽度(除windows任务栏之外)。

height返回显示屏幕的高度
width返回显示屏幕的宽度

    document.write(screen.availHeight);
    document.write("&nbsp;");
    document.write(screen.availWidth);
    document.write("<br/>");
    document.write(screen.height);
    document.write("&nbsp;");
    document.write(screen.width);

输出

738 1366
768 1366

四、navigator对象 包含有关浏览器的信息

   document.write("浏览器的名称: "+navigator.appName);
   document.write("<br/>");
   document.write("浏览器的平台和版本信息: "+navigator.appVersion);
   document.write("<br/>");
   document.write("浏览器的代码名: "+navigator.appCodeName);
   document.write("<br/>");
   document.write("浏览器的次级版本: "+navigator.appMinorVersion); //ie
   document.write("<br/>");
   document.write("浏览器的语言: "+navigator.browserLanguage); //ie
   document.write("<br/>");
   document.write("是否启用cookie: "+navigator.cookieEnabled);
   document.write("<br/>");
   document.write("浏览器的cpu等级: "+navigator.cpuClass); //ie
   document.write("<br/>");
   document.write("是否处于脱机模式: "+navigator.onLine); //ie
   document.write("<br/>");
   document.write("浏览器的操作系统平台: "+navigator.platform);
   document.write("<br/>");
   document.write("OS使用的默认语言: "+navigator.systemLanguage);//ie
   document.write("<br/>");
   document.write("由客户机发送服务器的user-agent头部的值: "+navigator.userAgent);
   document.write("<br/>");
   document.write("OS的自然语言设置: "+navigator.userLanguage);//ie

输出

浏览器的名称: Netscape
浏览器的平台和版本信息: 5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 3.0.30729; rv:11.0) like Gecko
浏览器的代码名: Mozilla
浏览器的次级版本: 0
浏览器的语言: zh-CN
是否启用cookie: true
浏览器的cpu等级: x86
是否处于脱机模式: false
浏览器的操作系统平台: Win32
OS使用的默认语言: zh-CN
由客户机发送服务器的user-agent头部的值: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 3.0.30729; rv:11.0) like Gecko
OS的自然语言设置: zh-CN 

相关文章

网友评论

      本文标题:javascript-History、Location、Scre

      本文链接:https://www.haomeiwen.com/subject/tzugoctx.html