以下彙整了幾段網頁製作中經常派上用場的實用小語法,涵蓋版面控制、快取、事件攔截與視窗操作等常見需求。
<body scroll="no">
<body style="overflow-y:hidden">
若希望每次開啟都不使用快取內容:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<body oncontextmenu="return false">
可以為連結定義多組狀態樣式:
a:active{}
a:link{}
a:visited{}
a.1:active{}
a.1:link{}
a.1:visited{}
在 Dreamweaver 的 CSS 面板中定義新的類別標示(例如 A.YOURS:LINK、A.YOURS:HOVER,YOURS 可換成自訂名稱),選取連結後點擊該標示即可套用,你就能定義任意多種滑鼠移入的變化效果。
<form name="form1" method="post" action="mailto:webmaster@jb51.net" enctype="text/plain">
<input type=submit>
</form>
1. 在 Flash 參數中加入 <param name="wmode" value=":transparent">。
2. 搭配 <body onblur=self.focus()>。
先準備好幾個不同尺寸的頁面(例如 htm1.htm 為 800×600、htm2.htm 為 1024×768),再於入口頁 index.htm 中判斷:
<html>
<head>
<script language=javascript>
<!--
function mHref(){
if (screen.width == 1024) location.href = "htm2.htm";
else if (screen.width == 800) location.href = "htm1.htm";
else return(false);
}
//-->
</script>
</head>
<body onload="mHref();">
</body>
</html>
透過 window.open 的第二、三個參數,可以控制新視窗只顯示位址列、狀態列、工具列或選單列,也能指定是否可調整大小。例如:
window.open('','new1','location=1') // 只顯示位址列
window.open('','','status=1') // 只顯示狀態列
window.open('','new2','toolbar=1,height=200,width=450') // 只顯示工具列
window.open('https://www.jb51.net','new6','resizable=1') // 無法顯示完整元件但可調整大小
也能用 newWin.document.write 動態寫入新視窗的內容,再透過 window.close() 關閉。