Javascript學習筆錄9(窗口屬性操作-status、背景色、title等)

1 改變狀態欄

window.status='welcome to my website

2 改變文本顏色

document.bgColor --背景色

document.fgColor -- 字體顏色

3 更改標題

document.title="Javascript學習筆錄9"+name+"</br>";

4 頁面最近的更改時間

document.lastModified

5 頁面的前導頁面

document.referrer

6 頁面的URl

document.URL

7 打開新的頁面

 window.open(url,name,features,replace)

這裏說明一下,document 和window的區別:

document(文檔對象)是window和frames對象的一個屬性,是顯示於窗口或框架內的一個文檔。

window對象是Javascript的高級對象,是頂層對象,即瀏覽器窗口。而document則是window的對象,由於window是頂級對象,

所以window.document.write 一般省略 window :document.write

8 打印頁面

window.print()

9 移動窗口
window.moveTo(x,y) 
參數x,y :窗口左上角的座標,單位爲像素。絕對位置,即屏幕位置
window.moveBy(dx,dy)
參數dx:窗口在水平方向移動的距離,單位爲像素。dx爲正值向右移動
       dy:窗口在垂直方向移動的距離,單位爲像素。dy爲正值向下移動。
相對位置,移動之後距離現在的位置。
10 改變窗體大小
window.resizeTo(width,height)
參數 width:窗口新寬度,單位爲像素。
        height:窗口新高度,單位爲像素
window.resizeBy(dwidth,dheight)
參數 dwidth:窗口寬度變化量,可正可負,單位爲像素。
        dheight:窗口高度變化量,可正可負,單位爲像素。
11 警告框
這個我經常用,有的時候項目裏面如果有asp的改動的話,一般來說我都是用alert()和console.info()去調試的。
12提示對話框
window.prompt(string,string)
13 確認對話框
window.confirm("do you like that?")
讓用戶確認。
具體代碼:

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

<!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>Javascript學習筆錄9</title>
</head>
<body οnlοad="window.status='welcome to my website'">
    <form id="form1" runat="server">
    <div>
    <a href =http://www.baidu.com>baidu</a>
    <input type="button" value="打印" οnclick="window.print()" />
    <br />
    水平方向<input type="text" name="x" value="20" />
    <br />
    垂直方向<input type="text" name="y" value="30" />
    <br />
    <input type="button" value="移動窗口到。。。。" οnclick="window.moveTo(document.form1.x.value,document.form1.y.value)" />
    <input type="button" value="移動窗口" οnclick="window.moveBy(document.form1.x.value,document.form1.y.value)" />
    <input type="button" value="改變窗口大小到。。。" οnclick="window.resizeTo(document.form1.x.value,document.form1.y.valu)" />
    <input type="button" value="改變窗口大小" οnclick="window.resizeBy(document.form1.x.value,document.form1.y.valu)" />
    </div>
    <script>
        document.bgColor="orange";
        document.write("background color is "+document.bgColor+"</br>");
        document.fgColor="blue";
        document.linkColor="red";
        name="Mouse"
        document.title="Javascript學習筆錄9"+name+"</br>";
        document.write(document.title);
        document.write("本頁面最後修改時間是"+document.lastModified+"</br>");
        document.write("本頁面URL:"+document.URL+"</br>");
        document.write("本頁面的引用頁面時:"+document.referrer+"</br>");
        window.open("http://www.baidu.com","taobao","width=200,heigh=200");
        document.write("正文</br>")
        alert("welcome page7")
        name=window.prompt("輸入用戶名","用戶名");
        document.write("welcome "+name+"<br>");
        confirms=window.confirm("are you sure");
        if(confirms==true) document.write("Iam sure")
        else document.write(" I am not sure")
    </script>
    <h2>pls look this text</h2>
     <a href =http://www.newegg.com.cn>Newegg.cn</a>

    </form>
</body>
</html>




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