JavaScriptの有効を促す

NOSCRIPTタグを使用して、その中でJavaScriptの有効を促すメッセージを表示。

<html> <head> <title>sample</title> <NOSCRIPT>JavaScripをONにしてください。<br></NOSCRIPT> </head>

クッキーの有効を促す

NavigatorオブジェクトのcookieEnabledプロパティを参照。

if(!navigator.cookieEnabled){ alert("このページを利用するにはクッキーを利用可能にして下さい"); } else{ document.write("cookieは有効です。"); }

右クリックの禁止

画像上で右クリックするとalertが出て、右クリックが出来ないようになっています。
cancelBubbleプロパティをtrueに設定すると、親オブジェクトにイベントが伝達するのを防ぎます。

function blockEvents(evt) { evt = (evt) ? evt : event; var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); // イベント要素はimgタグか? if (elem && elem.tagName && elem.tagName.toLowerCase() == "img") { if (evt.cancelBubble) { // 親オブジェクトにイベントを伝達しない evt.cancelBubble = true; } alert("右クリックは使えません。"); return false; } } document.oncontextmenu = blockEvents;

1文字ずつ表示

myMessage = "ご訪問ありがとうございます。"; i = 0; function Start(){ if (i<=myMessage.length) { document.myForm.typewrite.value = myMessage.substring(0, i); setTimeout('Start()',100); i++; } else { i=0; setTimeout('Start()',5000); } } <form name="myForm"> <input name="typewrite" type="text" size="40"> </form>

戻れないページ

Historyオブジェクトのreplace()メソッドは現在表示中のページを、履歴を残さずに別のページに置き換えることができます。
以下のサンプルは、中間のページに移動するのにocation.replace()を使っています。
これにより、最後のページで戻るボタンをクリックすると、最初のページが表示されます。


最初のページ 開始ページ <form action="#"> <input type="button" value="開始" onclick="location.href='replace-2.html'" /> </form> 2番目のページ 遷移ページ1(戻れないページ) <form action="#"> <input type="button" value="次へ" onclick="location.replace('replace-3.html')" /> </form> 3番目のページ 遷移ページ2(戻れないページ) <form action="#"> <input type="button" value="次へ" onclick="location.replace('replace-4.html')" /> </form> 最後のページ 最終ページ <form action="#"> <input type="button" value="戻る" onclick="history.back()" /> </form>