以下寫法可用於舊式瀏覽器:
<span style="cursor: hand" onClick="window.external.addFavorite('https://www.jb51.net','腳本之家')">收藏本站</span>
<span onclick="var strHref=window.location.href;this.style.behavior='url(#default#homepage)';this.setHomePage('https://www.jb51.net');">設為首頁</span>
注意:現代瀏覽器基於安全考量,通常不允許網頁直接修改首頁或加入收藏。
移除超連結底線:
<style type="text/css">
a:link { text-decoration: none; }
a:visited { text-decoration: none; }
a:hover { color: #ff00ff; text-decoration: underline; }
</style>
自動刷新或轉址:
<meta http-equiv="refresh" content="300; url=target.html">
<a href="javascript:location.reload()">重新整理</a>
<a href="javascript:history.back(-1)">返回上一頁</a>
跳出小視窗:
<script language="JavaScript">
window.open("window.html", "demo", "toolbar=no, status=no, menubar=no, scrollbars=no, resizable=no, width=468, height=60, left=200, top=50");
</script>
自動關閉視窗:
<script language="javascript">
var i = 20;
function clock() {
i = i - 1;
document.title = "本視窗將在" + i + "秒後關閉";
if (i > 0) setTimeout("clock();", 1000);
else self.close();
}
clock();
</script>
固定字級:
<style type="text/css">
body { font-size: 9pt; }
td { font-size: 9pt; }
</style>
防止被嵌入框架:
<script language="JavaScript">
if (self != top) { top.location = self.location; }
</script>
限制右鍵選單:
<script language="JavaScript">
function helpor() {
if (event.button == 2) alert('僅供瀏覽!謝謝!');
}
</script>
使用時,將 <body> 改為 <body onmousedown="helpor()">。這些技巧多屬於早期網頁開發常見做法,實際專案應依需求與瀏覽器支援情況調整。