ユーザ定義オブジェクトの別ウィンドウへの引継ぎ2
IEにはdialogという機能があり、オブジェクトを戻す機能を備えている。これを使ったらうまくいくだろうか。
showModalDialog.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title>showModalDialog</title> <script type="text/javascript" src="messageobject.js"></script> <script type="text/javascript"> <!-- var messageObject = new MessageObject(''); // --> </script> </head> <body> <h1>window.showModalDialog</h1> <form name="testForm"> <input type="submit" value="showModalDialog" onclick="messageObject = window.showModalDialog('dialog.html'); return false;"> <input type="submit" value="message" onclick="alert(window.messageObject.message); return false;"> <input type="submit" value="getMessage" onclick="alert(window.messageObject.getMessage()); return false;"> </form> </body> </html>
showModelessDialog.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title>showModelessDialog</title> <script type="text/javascript" src="messageobject.js"></script> <script type="text/javascript"> <!-- var messageObject = new MessageObject(''); // --> </script> </head> <body> <h1>window.showModelessDialog</h1> <form name="testForm"> <input type="submit" value="showModelessDialog" onclick="messageObject = window.showModelessDialog('dialog.html'); return false;"> <input type="submit" value="message" onclick="alert(window.messageObject.message); return false;"> <input type="submit" value="getMessage" onclick="alert(window.messageObject.getMessage()); return false;"> </form> </body> </html>
dialog.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title>dialog</title> <script type="text/javascript" src="messageobject.js"></script> <script type="text/javascript"> <!-- function set() { window.returnValue = new MessageObject(document.testForm.inputField.value); } // --> </script> </head> <body> <h1>dialog</h1> <form name="testForm"> <input type="text" name="inputField" value=""> <input type="submit" value="set" onclick="set(); return false;"> <input type="submit" value="message" onclick="alert(window.returnValue.message); return false;"> <input type="submit" value="getMessage" onclick="alert(window.returnValue.getMessage()); return false;"> <input type="submit" value="close" onclick="window.close(); return false;"> </form> </body> </html>
showModelessDialogによるモードレスダイアログはwindow.openのときと同じ。ただし、window.returnValueに値を代入しても、ダイアログを閉じないとwindow.showModelessDialogメソッドの戻り値を受け取れないので、ダイアログを閉じずに親ウィンドウのmessageボタンやgetMessageボタンを押すとエラーになる。showModalDialogによるモーダルダイアログは、どういうわけかプロパティのみ生きていてメソッドが失われてしまう。
不可解な動きだ。