プロが教えるわが家の防犯対策術!

初めて投稿します。今、showModalDialogで困っています。
まず画面上のボタンからjsファイル内のJavaScriptのメソッドを呼び出し、
その中でshowModalDialogを使って開いた小さな窓にカレンダーを表示します。
このカレンダー画面には月を選択するセレクトボックスがあり、
このセレクトボックスで月を変更した際にカレンダーをリロードする
処理を作ろうとしています。しかしこのリロードで「オブジェクトを
指定してください」というエラーが出てしまいます。
何がいけないのでしょうか・・・?

処理内容はこんな感じ・・・

1.jsファイル内のJavaScriptメソッドのshowModalDialog呼び出し部分
window.showModalDialog("modal.html");

2.呼び出されたmodal.html内ではbodyタグを以下のようにする
<body onLoad="javascript:loadPage();">

3.2で呼び出されたmodal.html内のJavaScript、loadPage()はこんな感じ
writePage()は1のjsファイル内の別のメソッド
function loadPage()
{
writePage();
}

4.3で呼び出されたjsファイル内のJavaScript、writePage()はこんな感じ
function writePage()
{
this.document.open();
this.document.writeln("Calendar");
this.document.writeln("<select onChange=\"javascript:loadPage();\">");
this.document.writeln("<option>1月");
this.document.writeln("<option>2月");
this.document.writeln("</select>");
}

A 回答 (2件)

test.html


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body onload="window.showModalDialog('modal.html')">
</body>
</html>

modal.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<script language="JavaScript" src="./Calendar.js"></script>
</head>
<body onLoad="writePage()">
</body>
</html>

Calendar.js
function writePage()
{
this.document.open();
this.document.writeln("<html><head><title></title>");
this.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
this.document.writeln("<script language=\"JavaScript\" src=\"./Calendar.js\"></script>");
this.document.writeln("</head><body>");
this.document.writeln("Calendar");
this.document.writeln("<select onChange=\"javascript:writePage();\">");
this.document.writeln("<option>1月");
this.document.writeln("<option>2月");
this.document.writeln("</select>");
this.document.writeln("</body></html>");
}

簡単なテストでこれなら取りあえずエラーは出ないと思います。
ハッキリ言ってなぜ補足で書かれたスクリプトでエラーが出るのか不明です。
ただ、上の例では文字化けするみたいですね。(windows98 IE6)

余分なことですが、この場合下のようにした方が簡単じゃないでしょうか。
Calendar.js
function writePage()
{
HTML = "Calendar" +
"<select onChange=\"javascript:writePage();\">"+
"<option>1月"+
"<option>2月"+
"</select>"
document.body.innerHTML = HTML
}
    • good
    • 0
この回答へのお礼

テストコードまで作成していただき、ありがとうございました。
確かにこのテストコードは私の環境でも動作しました。

どうやら問題はjsファイルのインポートのようです。
alertを出すだけの別のwritePage()を作って
this.document.writeln("<script>function writeAll(){alert(\"writeAll\");}</script>");
というように直書きするとちゃんとonChangeで呼ばれるのですが、これをCalendar.jsに
書き込んでインポートしようとすると、認識されていないのか、エラーがでます。

Resinを使ったウェブアプリケーションの開発での話なのですが、
環境依存の問題なのかもしれません。

差し当たり現在は別の手法で開発しようかと検討中です。どうもありがとうございました。

お礼日時:2007/01/03 15:49

<body onLoad="javascript:loadPage();">でドキュメントを書いているのでドキュメントの中身は


Calendar
<select onChange=\"javascript:loadPage();\">
<option>1月
<option>2月
</select>
となっていてloadPage()は無いから「オブジェクトを指定してください」となるのでは?

この回答への補足

あれ・・・そう言われてみれば・・・(汗

しかしですね、以下のように4の処理を変更しても
やっぱり同じエラーが出てしまったのです。
自分自身(jsファイル)をインポートすること自体が
いけないのでしょうか。。?

[変更内容]

(b)jsファイルをインポート。Calendar.jsとは
showModalDialogやwritePageがあるjsファイル
(d)onChangeで呼び出すJavaScriptメソッドを変更
(a),(c),(e)今まで割愛してましたが、念のため追加

4.3で呼び出されたjsファイル内のJavaScript、writePage()はこんな感じ
function writePage()
{
this.document.open();

(a)this.document.writeln("<html><head><title></title>");
(b)this.document.writeln("<script language=\"JavaScript\" src=\"./js/Calendar.js\"></script>");
(c)this.document.writeln("</head><body>");

this.document.writeln("Calendar");

(d)this.document.writeln("<select onChange=\"javascript:writePage();\">");

this.document.writeln("<option>1月");
this.document.writeln("<option>2月");
this.document.writeln("</select>");

(e)this.document.writeln("</body></html>");

}

補足日時:2007/01/03 13:30
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!