Javascript學習筆錄15(JS navigator 對象,cookies)

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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章