PIXNET Logo登入

以我為中心的宇宙

跳到主文

紀錄著宇宙中發生的大小事

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 10月 22 週三 200811:00
  • [JS] JavaScript Browser Detection

The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:appName - holds the name of the browser
appVersion - holds, among other things, the version of the browser
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".<html><body>
<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
</script>
</body></html>
The script below displays a different alert, depending on the visitor's browser:<html>
<head>
<script type="text/javascript">
function detectBrowser(){var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")
&& (version>=4)){
alert("Your browser is good enough!");
}
else
{
alert("It's time to upgrade your browser!");
}}
</script>
</head><body onload="detectBrowser()">
</body>
</html>
Reference:
W3School-JavaScript Browser Detection
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(155)

  • 個人分類:js
▲top
  • 10月 22 週三 200809:37
  • [JS] Javascript Document對象集合

document 文擋物件 - JavaScript腳本語言描述
———————————————————————
注:頁面上元素name屬性和JavaScript引用的名稱必須一致包括大小寫
否則會提示你一個錯誤資訊 “引用的元素為空或者不是物件\\\\\”
———————————————————————
物件屬性
document.title //設置文檔標題等價於HTML的title標籤
document.bgColor //設置頁面背景色
document.fgColor //設置前景色(文本顏色)
document.linkColor //未點擊過的鏈結顏色
document.alinkColor //啟動鏈結(焦點在此鏈結上)的顏色
document.vlinkColor //已點擊過的鏈結顏色
document.URL //設置URL屬性從而在同一視窗打開另一網頁
document.fileCreatedDate //檔建立日期,唯讀屬性
document.fileModifiedDate //檔修改日期,唯讀屬性
document.fileSize //檔大小,唯讀屬性
document.cookie //設置和讀出cookie
document.charset //設置字元集 簡體中文:gb2312
———————————————————————
常用物件方法
document.write() //動態向頁面寫入內容
document.createElement(Tag) //創建一個html標籤物件
document.getElementById(ID) //獲得指定ID值的對象
document.getElementsByName(Name) //獲得指定Name值的對象
document.body.appendChild(oTag)
———————————————————————
body-主體子物件
document.body //指定文檔主體的開始和結束等價於body>/body>
document.body.bgColor //設置或獲取物件後面的背景顏色
document.body.link //未點擊過的鏈結顏色
document.body.alink //啟動鏈結(焦點在此鏈結上)的顏色
document.body.vlink //已點擊過的鏈結顏色
document.body.text //文本色
document.body.innerText //設置body>…/body>之間的文本
document.body.innerHTML //設置body>…/body>之間的HTML代碼
document.body.topMargin //頁面上邊距
document.body.leftMargin //頁面左邊距
document.body.rightMargin //頁面右邊距
document.body.bottomMargin //頁面下邊距
document.body.background //背景圖片
document.body.appendChild(oTag) //動態生成一個HTML物件
常用物件事件
document.body.onclick=”func()” //滑鼠指標單擊物件是觸發
document.body.onmouseover=”func()” //滑鼠指標移到物件時觸發
document.body.onmouseout=”func()” //滑鼠指標移出物件時觸發
———————————————————————
location-位置子物件
document.location.hash // #號後的部分
document.location.host // 功能變數名稱+埠號
document.location.hostname // 功能變數名稱
document.location.href // 完整URL
document.location.pathname // 目錄部分
document.location.port // 埠號
document.location.protocol // 網路協定(http:)
document.location.search // ?號後的部分
documeny.location.reload() //刷新網頁
document.location.reload(URL) //打開新的網頁
document.location.assign(URL) //打開新的網頁
document.location.replace(URL) //打開新的網頁
———————————————————————
selection-選區子對象
document.selection
———————————————————————
images集合(頁面中的圖像)
a)通過集合引用
document.images //對應頁面上的img標籤
document.images.length //對應頁面上img標籤的個數
document.images[0] //第1個img標籤
document.images[i] //第i-1個img標籤
b)通過nane屬性直接引用
img name=”oImage”
document.images.oImage //document.images.name屬性
c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src
d)創建一個圖像
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
同時在頁面上建立一個img /標籤與之對應就可以顯示
———————————————————————-
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應頁面上的form標籤
document.forms.length //對應頁面上/formform標籤的個數
document.forms[0] //第1個/formform標籤
document.forms[i] //第i-1個/formform標籤
document.forms[i].length //第i-1個/formform中的控制項數
document.forms[i].elements[j] //第i-1個/formform中第j-1個控制項
b)通過標籤name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控制項名
c)訪問表單的屬性
document.forms[i].name //對應form name>屬性
document.forms[i].action //對應/formform action>屬性
document.forms[i].encoding //對應/formform enctype>屬性
document.forms[i].target //對應/formform target>屬性
document.forms[i].appendChild(oTag) //動態插入一個控制項
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設置為可視
document.all.oDiv.style.display=”none” //圖層設置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有物件的集合
只有ie支援此屬性,因此也用來判斷瀏覽器的種類*/
圖層物件的4個屬性
document.getElementById(”ID”).innerText //動態輸出文本
document.getElementById(”ID”).innerHTML //動態輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML
資料來源:http://www.ccvita.com/80.html
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(117)

  • 個人分類:js
▲top
  • 9月 07 週日 200820:23
  • [javascript] window.open 出現[object]


一般在.asp或.aspx網頁上加入一個HyperLink
並且設定NavigateUrl為"javascript:window.open('網址')"
在IE,FF都會開新視窗,但本身視窗(opener)會出現[object]or[object Window]的訊息
要解決這個問題,只要在多一個"void",如下所示,就可以解決了~
"javascript:void window.open('網址')"
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(416)

  • 個人分類:js
▲top
  • 9月 07 週日 200819:57
  • [javascript] insertAdjacentHTML 點用?

insertAdjacentHTML("插入位置參數","欲插入的element") 待續。
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(73)

  • 個人分類:js
▲top
  • 9月 06 週六 200821:30
  • [javascript] use insertBefore insert element


我的結構大概長這樣
<td id=tdCity>
&nbsp&nbspradio1<input type=radio name="chosen">
&nbsp&nbspradio2<input type="radio" name="chosen">
&nbsp&nbsp<select name="city" id="city"></select>
&nbsp&nbsp<select name="town"></select>
</td>
照理說city dropdownlist的parentNode就是tdCity
<script>
&nbsp&nbspvar Insertpos = document.getElementById("tdCity");
&nbsp&nbspvar refChild = document.getElementsByName("city");
&nbsp&nbsprefChild.parentNode.insertBefore(newNode,refChild);
&nbsp&nbsp//Insertpos.insertBefore(newNode,refChild); (效果同上)
</script>
但是,照著上面這樣寫會出現parentNode是null的錯誤訊息
後來把 var refChild = document.getElementsByName("city");
改成 var refChild = document.getElementById("city");
就ok了,做個記錄。
參考資料:
JavaScript之appendChild VS insertBefore
JavaScript:createElement
javascript---使用createElement动态创建HTML对象
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(183)

  • 個人分類:js
▲top
  • 9月 03 週三 200816:46
  • js視窗操作

如果你今天透過非 window.open的方式(也就是透過使用者執行desktop application)打開一個browser視窗,而且你的網頁中要執行javascript的window.close(),則browser會問使用者是不是真的要把這個視窗給關閉。之所以有這一層的防護是因為安全的理由(避免一個browser window無聲無息的就關閉了)。如果該視窗是透過javascript的window.open打開的,那麼就不會有這個對話框。
EX:<a href="#" onClick="window.open('abc.aspx?no=123','_new' ,'height=300,width=800,toolbar=no,status=yes,resizable=yes,scrollbars=yes');window.close();">test</a>";
OR:<a href="javascript:void window.open('abc.aspx?no=123','_new' ,'height=300,width=800,toolbar=no,status=yes,resizable=yes,scrollbars=yes');">連結</a>";
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(17)

  • 個人分類:js
▲top
  • 8月 11 週一 200813:05
  • javascript opener 點用?

opener就是指這個視窗是從哪裡開啟的, 例如M視窗有如下語句
<a href="n.html" target="_blank">
這樣, 按下M視窗這條Link的話, 會開啟另一視窗N, 這時M視窗便是N視窗的opener, N視窗可通過opener來控制M視窗的各種屬性, 如opener.document.***, opener.form.***
(繼續閱讀...)
文章標籤

以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣(45)

  • 個人分類:js
▲top
1

個人資訊

以我為中心的宇宙
暱稱:
以我為中心的宇宙
分類:
數位生活
好友:
累積中
地區:

熱門文章

  • (6)打起精神哪...rhea媽媽
  • (7)很不diary的diary 2009.3.18
  • (5)Delete Terminal Remote Connections
  • (1,447)"無法使用 '' ; 檔案已在使用中。"
  • (206)Windows內建程式開啟指令
  • (117)[JS] Javascript Document對象集合
  • (155)[JS] JavaScript Browser Detection
  • (125)Keep Sql Command in ViewState
  • (420)解決使用MasterPage,javascript取不到控制項
  • (122)GridView和FormView 加入選擇日期的視窗的解法

文章分類

  • Tool (2)
  • MFC (4)
  • 硬體 (1)
  • English (4)
  • 生活資訊 (1)
  • Blogger Hack (7)
  • 軟體 (4)
  • GIS (1)
  • 工作 (0)
  • 雙子座 (2)
  • 悸 (2)
  • 合購 (8)
  • 系統 (2)
  • AJAX (1)
  • CSS (5)
  • 程式 (21)
  • 暫存 (5)
  • js (7)
  • ASP.NET (5)
  • DataBase (8)
  • Windows (2)
  • 閒話家常 (13)
  • 記 (1)
  • 口合呢 (0)
  • 未分類文章 (1)

最新文章

  • 可以吃的戒指
  • [DOS] PUSHD and POPD
  • [JS/JQuery] Re-Format for Compress JS Code by JSBeautifier
  • 儲物盒 家樂福 VS iKea
  • [MFC/XML] Read/Writer XML
  • [MFC/VC] Detect file exist or not
  • [MFC] cannot convert from _TCHAR** to RPC_WSTR*
  • [MFC] Create GUID
  • [SVN] What's SVN
  • Walkthrough 係咩野?

文章精選

文章搜尋

參觀人氣

  • 本日人氣:
  • 累積人氣: