JavaScript のバックアップ(No.10) - PukiWiki

FrontPage

Tips
[edit]

JavaScriptで画像認証コードを生成するサンプルJavaScript0001?
このページのトップへ

画面を閉じる時のメッセージを出さないように
[edit]

<script language=javascript>
function CloseWindow()
{
   window.open('','_self','');
   window.close();
}
</script>
<a href="" onclick="CloseWindow();">Testing Close Window</a>


このページのトップへ

モーダルダイアログを表示する
[edit]

モーダルダイアログを表示するにはモーダルダイアログを表示するには showModalDialog() を使用します。モーダルダイアログ表示中は、親ウィンドウの操作は一切禁止されます。

<script type="text/javascript">
<!--
function func() {
 var args = new Array();
 args[0] = window;
 args[1] = document.f1.t1.value;
 args[2] = document.f1.t2.value;
 val = showModalDialog("test2.htm", args,
     "dialogHeight:100px;dialogWidth:300px");
}
// -->
</script>

<form name="f1">
<input type="text" name="t1">
<input type="text" name="t2">
<input type="button" value="OK" onclick="func()">
</form> 

表示されるダイアログの内容も HTML で記述します。dialogArguments で親ウィンドウからの値を取得することができます。また、returnValue で親ウィンドウに値を返すことができます。

<html>
<head>
<title>モーダルダイアログ</title>
<script type="text/javascript">
<!--
var win;
function init() {
  win = window.dialogArguments[0];
 document.f2.t1.value = window.dialogArguments[1];
 document.f2.t2.value = window.dialogArguments[2];
}
function OnOK() {
 win.document.f1.t1.value = document.f2.t1.value;
 win.document.f1.t2.value = document.f2.t2.value;
 window.returnValue = true;
 window.close();
}
// -->
</script>
</head>
<body onload="init()">
<form name="f2">
<input type="text" name="t1">
<input type="text" name="t2">
<input type="button" value="OK" onclick="OnOK()">
</form>
</body>
</html>


このページのトップへ

戻るボタンを無効化する
[edit]

ポイント

方法一:
戻るボタンがいつも灰色でクリックできない状態になります。

function redirect(url)
{
    var Backlen=history.length;
    history.go(-Backlen);
    window.location.replace(url);
}

方法二:
戻るボタンがクリックできる状態ですが、戻る動作がしません。

window.history.forward(1);

※以上の方法は、IEしか動作しません。FireFox上で動作できるため、下記のようにbodyタグにonunload属性を着ける必要があります。

<body onunload="">
このページのトップへ

JavaScriptでページのレンダリング時間をミリ秒単位で簡易計測する
[edit]

var start = new Date();
function timecount() {
  var end = new Date();
  var diff = end.getTime() - start.getTime();
  alert(diff);
}

<body onload="timecount()">
このページのトップへ

二重送信防止
[edit]

function DisableButton(button)
  {
     button.disabled = true;
     button.value = 'Submitting';
     button.form.submit();
  }

 HTML側の使用例:

<input type="submit" name="SubmitButton" id="SubmitButton"
         value="Submit"
         onclick="DisableButton(this);" />

コメント:




トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

yVoC[UNLIMITȂ1~] ECirŃ|C Yahoo yV LINEf[^[Ōz500~`I


z[y[W ̃NWbgJ[h COiq 萔O~ył񂫁z COsیI COze