Javascript学习笔录15(JS navigator 对象,cookies)

25 篇文章 0 订阅
16 篇文章 0 订阅

1 navigator是一个独立的对象,他用于提供用户所使用的浏览器以及操作系统等信息,以navigator对象属性的形式来提供。

navigator的用法 location的用法

2 cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案。

具体代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Js12.aspx.cs" Inherits="Javascript_Js12" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body οnlοad="makeCookie()">
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>
<script>
document.write("navigator 对象的属性:"+"</br>");
document.write("appcodename:"+navigator.appCodeName+"<br>")
document.write("appname::"+navigator.appName+"<br>")
document.write("appversion:"+navigator.appVersion+"<br>")
document.write("platform:"+navigator.platform+"<br>")
document.write("userAgent:"+navigator.userAgent+"<br>")
document.write("navigator对象的方法"+"<br>")
document.write("javaEnabled():"+navigator.javaEnabled()+"</br>")
if(navigator.appName.indexOf("Microsoft")!=-1){
document.write("用户浏览器是微软的IE浏览器"+"<br>")}
else if(navigator.appName.indexOf("Netscape")!=-1){
document.write("用户浏览器是netscape的netscape浏览器"+"<br>")}
if(navigator.appVersion.indexOf("4.0")!=-1){
document.write("this browser is not 4.0 compliant.")
}
else{
document.write("you are using a version 4.0compatible browser")}
document.write("location对象的属性"+"<br>")
document.write("hash"+location.hash+"<br>")
document.write("hostname"+location.hostname+"<br>")
document.write("host"+location.host+"<br>")
document.write("href"+location.href+"<br>")
document.write("port"+location.port+"<br>")
document.write("search"+location.search+"<br>")

function makeCookie()
{
    if(document.cookie)
    {
        name=prompt("请输入名字");
        document.cookie="name="+name+";";
        namestart=document.cookie.indexOf("="); 
        nameend=document.cookie.lastIndexOf(";");
        document.write("you name is "+document.cookie.substring(namestart+1,nameend)+"</br>")
    }
}

</script>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值