您的位置:首页 > Web前端 > JavaScript

Js学习之道: Javascript学习笔录15(JS navigator 对象,cookies)

2013-09-18 20:37 561 查看
1 navigator是一个独立的对象,他用于提供用户所使用的浏览器以及操作系统等信息,以navigator对象属性的形式来提供。

navigator的用法 location的用法

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

具体代码:

[html] view
plaincopy

<%@ 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 onload="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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐