Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: Общие вопросы > Модальное окно, возврат значений


Автор: proger 28.11.2005, 10:07
На главной странице вызываю модальное окно
Код

<script>
function opens(){
 window.status=\"\";
 strFeatures=\"dialogWidth=500px;dialogHeight=320px;scrollbars=yes;center=yes;border=thin;help=no;status=no\";
 strTitle=window.showModalDialog(\"inc/system/alldostupny/spravschetov.php\",\"NewWindows\",strFeatures);
 window.status=\"Ñ÷åòà êëèåíòà\";
}
<!--

</script>

Потом из этого модального окна хочу вернуть значение в поле данные так:
Код

<script language=\"JavaScript\">
<!--
function Insert(in1)
{
    window.opener.document.pporuch.iik.value = in1;
    window.close();
}
//-->
</script>

Он ругается на window.opener.document, что это значит?

Автор: Ciber SLasH 28.11.2005, 14:16
Модальный диалог не имеет никаких отношений с родительским окном.
Для взаимодействия модального окна с главным существует: window.returnValue — свойство у модального окна для возврата значения в главное окно; результат вызова метода window.showModalDialog() — то, что возвратило модальное окно.

Всё это выглядит так:
main.htm
Код
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content='text/html; charset=windows-1251'>
<meta name="Generator" content='EditPlus 2.20.211'>
<meta name="Author" content='Ciber SLasH'>
<title>JavaScript :: Пример работы с showModalDialog (IE only)</title>
<script type='text/javascript'>
function doShowModal(obj) {
var args = [obj.arg1.value, obj.arg2.value, obj.arg3.value];
var ft = "dialogWidth: 300px; dialogHeight: 240px; center: yes; help: no; resizable: yes; status: no";
var Result = window.showModalDialog("modal.htm", args, ft);

    document.getElementById('rez').innerText = Result;

return false;
}
</script>
<style type='text/css'>
form {margin: 3px 0}
button {margin-top: 5px}
#rez {height: 100px; border: 2px solid black}
</style>
</head>

<body>
<fieldset><legend>[ showModalDialog ]</legend>
<form onSubmit='return doShowModal(this)'>
Аргумент №1: <input type="text" name="arg1" tabindex="1"> Аргумент №2: <input type="text" name="arg2"> Аргумент №3: <input type="text" name="arg3"><br>
<center><button type="submit">Показать диалог</button></center>
</form>
</fieldset>
<br>Результат:
<div id='rez'></div>
</body>
</html>


modal.htm
Код
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content='text/html; charset=windows-1251'>
<meta http-equiv="MSThemeCompatible" content='Yes'>
<meta name="Generator" content='EditPlus 2.20.211'>
<meta name="Author" content='Ciber SLasH'>
<title>JavaScript :: showModalDialog()</title>
<script type='text/javascript'>
function setValues() {
var values = window.dialogArguments;
var form = document.getElementById('myForm');

    if (values) {
        form.arg1.value = values[0];
        form.arg2.value = values[1];
        form.arg3.value = values[2];
    }
}
</script>
<style type='text/css'>
body {margin: 5px}
#myForm input {background: buttonFace}
</style>
</head>

<body onLoad='setValues()'>
<fieldset><legend>[ From "main.htm" ]</legend>
<form id='myForm'>
Аргумент №1: <input type="text" name="arg1" tabindex="1" readonly><br>
Аргумент №2: <input type="text" name="arg2" readonly><br>
Аргумент №3: <input type="text" name="arg3" readonly>
</form>
<form onSubmit='window.returnValue = this.retValue.value; self.close(); return false'>
Возвратить значение в главное окно:<br>
<input type="text" name="retValue" size="28"><input type="submit" value="Return">
</form>
</fieldset>
</body>
</html>


Только учти, что метод window.showModalDialog() работает только в IE. Лучше юзай всплывающее окно: window.open()

Автор: proger 28.11.2005, 15:55
ясно, спасибо!
Добавлено @ 15:57
спасибо!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)