Zdravím,
existuje v javascriptu něco jako confirn, ale abych mohl nastavit, popis jednotlivých tlačítek? popřípadě jde udělat dialogové okno, do kterého můžu vložit libovolný počet svých tlačítek??
Fórum › JavaScript, AJAX, jQuery
Dialogové okno s možnostmi

Co takhle modální okno, na stylování bych se vybodl - asi jde hlavně o popis tlačítek viď?
Předávaní výsledku jde více způsoby, myslím že existuje specialní modal.dialog s returnValue nebo tak nějak.
Anebo je před uzavřením přiřadit: opener.variable=XXX; self.close()
Modální okno je idealní způsob protože js kód pokračuje až po jeho uzavření.
Popis: http://www.webreference.com/js/column90/index.html[Modal and Modeless Dialog Boxes]
Příklad:
<html><head><title>CustomConfirm</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script>
/******************************************* zde se definují rozměry okna ***************/
vyska= 160; sirka= 600; /* nula->automaticky */
/******************************************* konec definice parametrů okna ***************/
function myConfirm(){ /* obsah dialogového okna je definován v souboru callee.html */
return window.showModalDialog("./callee.html","",
"dialogHeight:"+vyska+"px; dialogWidth:"+sirka+"px; center:yes;" )
}
</script>
</head>
<body onload='alert("Výsledek je :" + myConfirm())'> <!-- OTEVŘE DIALOG A PO AKCI VYPÍŠE VÝSLEDEK -->
</body>
</html>
Soubor: callee.html
<html><head><title></title></head>
<body >
<form id="frm">
<h5> Zadal jsi heslo - chceš použít jeho zapamatování pro automatické přihlášení? <h5>
</form>
<script>
function button(txt,sirka,result,nextline){
var f,p,b,len;
f=document.getElementById("frm");
f.style.textAlign="center";
document.getElementsByTagName("h5")[0].style.marginTop ="1ex";
b=document.createElement("BUTTON");
b.appendChild(document.createTextNode(txt));
f.appendChild(b);
if (nextline) f.appendChild(document.createElement("BR"));
b.style.margin = "1ex 0ex 0ex 2em";
b.style.padding = "2px 1ex";
if (sirka) b.style.width = sirka+"px";
b.style.textAlign ="center";
b.onclick=function(){eval("returnValue="+result+";window.close()")};
}
/**************************** zde se definují tlačítka *******************/
button("Zapamatovat",300,1,1); /* R=1 šířka=300px odřádkovat */
button("Odložit na později",0,2); /* R=2 */
button("Ignorovat",0,0); /* R=0 */
/***************************** konec definice tlačítek ******************/
</script>
</body></html>
UKÁZKA: http://exstream.atlasweb.cz/ModeDialog/caller.html
Předchozí ukázka funguje jen v IE.
Navíc je třeba vytvořit samostatný soubor s confirm dialogem.
Tento kód těmito nedostatky netrpí:
<html><head><title>CustomConfirm</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script>
var win=null,returnValue=0;
function myConfirm(js_code){
/**************************************** zde se definují parametry okna ***************/
var vyska= 160, sirka= 600,
napis= "Zadal jsi heslo - chceš použít jeho zapamatování pro automatické přihlášení?";
/****************************************** konec definice parametrů okna ***************/
function button(txt,sirka,result,nextline){
var f,p,b,len;
f=win.document.getElementById("frm");
f.style.textAlign="center";
win.document.getElementsByTagName("h5")[0].style.marginTop ="1ex";
b=win.document.createElement("BUTTON");
b.appendChild(win.document.createTextNode(txt));
f.appendChild(b);
if (nextline) f.appendChild(win.document.createElement("BR"));
b.style.margin = "1ex 0ex 0ex 2em";
b.style.padding = "2px 1ex";
if (sirka) b.style.width = sirka+"px";
b.style.textAlign ="center";
b.onclick=function(){win.opener.returnValue=result;win.close()};
}
win=window.open("about:blank","_blank",
"left="+(screen.availWidth-sirka)/2+",top="+(screen.availHeight-vyska)/2+",width="+sirka+",height="+vyska);
win.focus(); setTimeout(function(){win.focus()},1500);
win.document.open();
win.document.write("<html><head><title>CONFIRM</title></head><body onunload='opener.win=null'>" +
"<form id='frm'><h5>" + napis + "</h5></form></body></html>");
win.document.close();
/**************************** zde se definují tlačítka *************************/
button("Zapamatovat",300,1,1); /* R=1 šířka=300px odřádkovat */
button("Odložit na později",0,2); /* R=2 */
button("Ignorovat",0,0); /* R=0 */
/* R=0 je-li dialog ukončen uzavřením */
/***************************** konec definice tlačítek **************************/
returnValue=0;
var f=setInterval(function(){if(!win){clearTimeout(f);js_code()}},200);
}
/* POUŽITÍ: */
/* 1. JS kód před confirmem: */ function part1() { alert("Spustíme confirm") }
/* 2. JS kód po confirmu: */ function part2() { alert("Výsledek je: " + returnValue) }
/* Výsledek confirmu: gl.proměnná returnValue */
function program(){
part1();
myConfirm(part2)
}
</script>
</head>
<body onload='program()'>
</body>
</html>
Ukázka: http://exstream.atlasweb.cz/ModeDialog/caller_plus.html
Nevěděl by někdo jak donutit i Operu aby zobrazila dialog uprostřed okna (a ne vpravo dole) ???

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 13 hostů
Podobná vlákna
Vlastní dialogové okno v C# — založil paashi
Jtable,Dialogové okno ... — založil elvis
Dialogove okno showModalDialog — založil george
Dialogove okno inak — založil marioff
Win32 API - dialogové okno — založil vollf82
Moderátoři diskuze