開發過程中,總有一些「用得到但記不住」的小技巧。本文整理了頁面緩存控制、iframe 交互、滾動條定製、光標樣式、表單郵件提交、伺服器變數獲取、文字豎排、收藏夾圖標等高頻代碼片段,供快速查閱。
<head>)<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
<meta http-equiv="expires" content="Wed, 26 Feb 1978 08:21:57 GMT">
jQuery AJAX 全域禁用緩存:
$.ajaxSetup({ cache: false });
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type="submit">
</form>
window.opener.location.reload()document.getElementById('iframeId').contentWindow.fn()window.parent.fn()<!-- 指定開窗尺寸 -->
<body onload="top.resizeTo(300,200);">
<!-- 隱藏垂直滾動條 -->
<body style="overflow-y:hidden">
<!-- 隱藏水平滾動條 -->
<body style="overflow-x:hidden">
<!-- 完全隱藏滾動條 -->
<body scroll="no"> 或 <body style="overflow:hidden">
<a href="#" onfocus="this.blur()"><img src="logo.jpg" border="0"></a>
<style>
body {
background-image: url(logo.gif);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed; /* 關鍵屬性 */
}
</style>
| 值 | 效果 |
|---|---|
| auto | 瀏覽器預設 |
| default | 標準箭頭 |
| pointer / hand | 手形(可點擊) |
| wait | 等待(沙漏/圈圈) |
| text | I 形(文字輸入) |
| move | 移動十字箭頭 |
| not-allowed | 禁止(斜線圓圈) |
| help | 問號 |
| e-resize, n-resize, ne-resize... | 各方向縮放 |
<!-- 客戶端 IP -->
<%= Request.ServerVariables("HTTP_X_FORWARDED_FOR") %>
<!-- 若為空則用 REMOTE_ADDR -->
<!-- 伺服器資訊 -->
伺服器名稱: <%= Request.ServerVariables("SERVER_NAME") %>
伺服器 IP: <%= Request.ServerVariables("LOCAL_ADDR") %>
伺服器埠: <%= Request.ServerVariables("SERVER_PORT") %>
伺服器時間: <%= now %>
IIS 版本: <%= Request.ServerVariables("SERVER_SOFTWARE") %>
腳本超時: <%= Server.ScriptTimeout %>
文件物理路徑: <%= Server.MapPath(Request.ServerVariables("SCRIPT_NAME")) %>
CPU 數量: <%= Request.ServerVariables("NUMBER_OF_PROCESSORS") %>
作業系統: <%= Request.ServerVariables("OS") %>
<style>
.shupai { writing-mode: tb-rl; } /* IE 專屬,現代瀏覽器請用 writing-mode: vertical-rl; */
</style>
<link rel="Shortcut Icon" href="favicon.ico">
Function formatStr(str, len)
If Len(str) > len Then
formatStr = Left(str, len) & "..."
Else
formatStr = str
End If
End Function
<script>
function DrawImage(img) {
var image = new Image();
image.src = img.src;
if (image.width > 0 && image.height > 0) {
if (image.width > 120) img.width = 120;
else img.width = image.width;
img.alt = image.width + "×" + image.height;
}
}
</script>
<img src="..." onload="DrawImage(this)">
<meta http-equiv="refresh" content="0; url=/target-page.html">
提示:部分代碼為經典 ASP / VBScript 語法,現代項目請根據技術棧(PHP、Node.js、ASP.NET Core 等)轉換對應寫法。