用户自定义对话框返回值的问题
我在制作在线编辑器的时候,自定义了个图片上传对话框,当单击时,弹出了该对话框,当单击上传后,文件上传到服务后自动生成一个文件(不是上传时的文件名),现在怎样才能得到该文件名并且在编辑器窗口中显示出来呢?请高手解答 问题点数:100、回复次数:18Top
1 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 20:25:14 得分 0
如果你的对话框是用 window.open 出来的
就用
<script>
opener.document.all.编辑器名.value+=上传后文件名
</script>
如果你的对话框是用 showModalDialog
在调用时
<script>
var fname=showModalDialog('xxxx.htm')
</script>
关闭窗口时
<script>
window.returnValue=上传后的文件;
window.close();
</script>
fname就得到了上传后的文件
怎么处理都行Top
2 楼qrlvls( 空 气 )回复于 2005-01-28 20:26:29 得分 0
upTop
3 楼tigerlgf(南湖学士)回复于 2005-01-28 20:39:03 得分 0
我用的是showModalDialog,但是还是不行
Top
4 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 20:43:59 得分 0
showModalDialog关闭事件的代码贴出来?Top
5 楼tigerlgf(南湖学士)回复于 2005-01-28 20:47:14 得分 0
//这是上传文件对话框的源代码:
<!--#include file="upload/UpLoadClass.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
</head>
<body bgcolor=menu topmargin="0">
<script language="javascript">
function checkform(){
if(PicForm.F1.value==""){
window.alert("文件不能为空!");
window.frames("Contents").document.body.innerHTML="asgasdgf";
return false;
}
PicForm.submit();
}
</script>
<form method="POST" enctype="multipart/form-data" action="pic.asp" name="PicForm" target=_self>
<p><input type="file" name="F1" size="13"><input type="button" value="上传" name="B1" onclick="checkform()"></p>
<input type="hidden" name="Command" value="Up">
</form>
<%
dim request2
set request2 = new UpLoadClass
request2.MaxSize =1536000
request2.open()
if request2.form("Command")="Up" then
if request2.form("F1_Err")=0 then
response.write "<script language=""javascript"">"
response.write "window.returnValue='" & request2.form("F1") & "';"
response.write "window.close();"
response.write "</script>"
else
response.write "<br>文件上传时出现错误!<br>"
end if
end if
%>
</body>
</html>Top
6 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 20:54:59 得分 0
噢,风声无组啊
代码好象没什么问题
主文件处理showModalDialog的代码?Top
7 楼tigerlgf(南湖学士)回复于 2005-01-28 20:56:32 得分 0
''这是主程序处理的代码:
function forPicture(){
var arr =showModalDialog("upfile.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr !=null){
var s;
s=Contents.document.body.innerHTML;
s = s + "<img src='"+arr & "'>"
Contents.document.body.innerHTML = s;
}
Top
8 楼tigerlgf(南湖学士)回复于 2005-01-28 21:15:37 得分 0
有谁知道原因吗?在线等答案!Top
9 楼chonboy(一只来自南方的羊)回复于 2005-01-28 21:58:29 得分 0
文件上传成功后,文件名知道撒?
生成一段JS把文件名赋到指定的表单域内,如下:
<%
dim strFilename '上传文件名
dim strInput '文件名赋给的INPUT名字,比如 frm.FileName
strInput=Request.querystring("InputName")
'...上传处理,得到文件名 strFileName="123456.gif"
Response.Write "<Script Language=JavaScript>"
Response.Write "opener.document."&strInput&".value='"&filename&"';"
Response.Write "window.close();"
Response.Write "</Script>"
%>Top
10 楼tigerlgf(南湖学士)回复于 2005-01-28 22:07:17 得分 0
我把我的主要代码一起贴出来吧,请大家帮忙!
'edit.js文件
<script language="javascript">
function InitDocument(){
Contents.document.open();
//Contents.document.write("<div></div>");
Contents.document.close();
Contents.document.designMode="On";
}
function Format(what,opt){
if (opt=="removeFormat")
{
what=opt;
opt=null;
}
if (opt==null) Contents.document.execCommand(what);
else Contents.document.execCommand(what,"",opt);
Contents.focus();
}
function doSelectClick(str, el) {
var Index = el.selectedIndex;
if (Index != 0){
el.selectedIndex = 0;
if (el.id == "specialtype")
specialtype(el.options[Index].value);
else
Format(str,el.options[Index].value);
}
}
function fortable(){
var arr = showModalDialog("table.html", "", "dialogWidth:13.5em; dialogHeight:5.5em; status:0");
if (arr != null){
var ss;
ss=arr.split("*")
row=ss[0];
col=ss[1];
var string;
string="<table border=1>";
for(i=1;i<=row;i++){
string=string+"<tr>";
for(j=1;j<=col;j++){
string=string+"<td></td>";
}
string=string+"</tr>";
}
string=string+"</table>";
content=Contents.document.body.innerHTML;
content=content+string;
Contents.document.body.innerHTML=content;
}
else Contents.focus();
}
function foreColor(){
var arr = showModalDialog("selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr != null) Format('forecolor',arr);
else Contents.focus();
}
function forPicture(){
var arr =showModalDialog("upfile.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr !=null){
var s;
s=Contents.document.body.innerHTML;
s = s + "<img src='"+arr & "'>"
Contents.document.body.innerHTML = s;
}
}
function help(){
alert("在线编辑器版本1.0\n 制作人:tiger");
}
Top
11 楼tigerlgf(南湖学士)回复于 2005-01-28 22:11:21 得分 0
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="STYLESHEET" type="text/css" href="edit.css">
<title>在线编辑器</title>
<script language="javascript" src="edit.js"></script>
</head>
<body onload="InitDocument()">
<div align="center">
<table border="0" cellpadding="0" style="border-collapse: collapse" width="800" id="table1" height="353">
<tr>
<td height="58">
<table border="0" cellpadding="0" style="border-collapse: collapse" id="table3" width="454">
<tr>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('CreateLink');"><img border="0" src="images/wlink.gif" width="22" height="22" alt="插入超级链接"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="forPicture();"><img border="0" src="images/img.gif" width="22" height="22" alt="插入图片"></div></td>
<td width="25" height="25" align="center" style="border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('InsertHorizontalRule')"><img border="0" src="images/hr.gif" width="16" height="16" alt="插入水平线"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="help()"><img border="0" src="images/help.gif" width="24" height="24" alt="帮助"></div></td>
<td width="200">
</td>
</tr>
</table>
<div align="center">
<table border="0" cellpadding="0" style="border-collapse: collapse" width="800" id="table4" height="27">
<tr>
<td width="432">
<table border="0" cellpadding="0" style="border-collapse: collapse" id="table5">
<tr>
<td width="25" height="25" align="center" style="border-left-style: solid; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-right-style:solid">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="forColor();">
<img border="0" src="images/fgcolor.gif" width="23" height="22" alt="字体颜色"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('bold')"><img border="0" src="images/bold.gif" width="16" alt="加粗" height="16"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('italic')">
<img border="0" src="images/italic.gif" width="16" height="16" alt="斜体"></div></td>
<td width="25" height="25" align="center" style="border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('underline')">
<img border="0" src="images/underline.gif" width="16" height="16" alt="下划线"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('justifyleft')">
<img border="0" src="images/aleft.gif" width="17" height="16" alt="左对齐"></div></td>
<td width="25" height="25" align="center">
<div class="Btn" onmouseover="this.className='BtnMouseOverUp'" onmousedown="this.className='BtnMouseOverDown'" onmouseout="this.className='Btn'" onclick="Format('justifycenter')">
<img border="0" src="images/center.gif" width="17" height="16" alt="居中"></div></td>
</tr>
</table>
</td>
<td width="148"> </td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<iframe name="Contents" width="785" height="285">浏览器不支持嵌入式框架,或被配置为不显示嵌入式框架。
</iframe></td>
</tr>
</table>
</div>
</body>
</html>
Top
12 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 22:15:56 得分 0
主文件
===================================================
<script>
function forPicture(){
var arr =showModalDialog("pic.asp", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr !=null){
s=Contents.document.body.innerHTML;
s = s + "<img src='"+arr + "'>" ;
Contents.document.body.innerHTML = s;
}
}
</script>
<input type=button value="upload" onclick="forPicture();">
<iframe name=Contents width=300 heigth=300></iframe>
pic.asp(showmadol的窗口)
===========================
<!--#include file="upload/UpLoadClass.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
</head>
<base target="_self">
<body bgcolor=menu topmargin="0">
<script language="javascript">
function checkform(){
if(PicForm.F1.value==""){
window.alert("文件不能为空!");
window.frames("Contents").document.body.innerHTML="asgasdgf";
return false;
}
PicForm.submit();
}
</script>
<form method="POST" enctype="multipart/form-data" action="pic.asp?command=up" name="PicForm" >
<p><input type="file" name="F1" size="13"><input type="button" value="上传" name="B1" onclick="checkform()"></p>
</form>
<%
if request("command")="up" then
dim request2
set request2 = new UpLoadClass
request2.MaxSize =1536000
request2.open()
if request2.form("F1_Err")=0 then%>
<script language="javascript">
window.returnValue='<%= request2.form("F1")%>';
window.close();
</script>
<%
else
response.write "<br>文件上传时出现错误!<br>"
end if
end if
%>
</body>
</html>
Top
13 楼tigerlgf(南湖学士)回复于 2005-01-28 22:17:48 得分 0
/upfile.html文件
<!--#include file="upload/UpLoadClass.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
</head>
<body bgcolor=menu topmargin="0">
<script language="javascript">
function checkform(){
if(PicForm.F1.value==""){
window.alert("文件不能为空!");
window.frames("Contents").document.body.innerHTML="asgasdgf";
return false;
}
PicForm.submit();
}
</script>
<form method="POST" enctype="multipart/form-data" action="pic.asp" name="PicForm" target=_parent>
<p><input type="file" name="F1" size="13"><input type="button" value="上传" name="B1" onclick="checkform()"></p>
<input type="hidden" name="Command" value="Up">
</form>
<%
dim request2
set request2 = new UpLoadClass
request2.MaxSize =1536000
request2.open()
if request2.form("Command")="Up" then
if request2.form("F1_Err")=0 then
response.write "<script language=""javascript"">"
response.write "window.returnValue='" & request2.form("F1") & "';"
response.write "window.close();"
response.write "</script>"
else
response.write "<br>文件上传时出现错误!<br>"
end if
end if
%>
</body>
</html>Top
14 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 22:21:32 得分 100
有几个问题提醒你一下
1.
s = s + "<img src='"+arr & "'>"
你这句,就不知所谓了,应为
s = s + "<img src='"+arr + "'>"
2.
<form method="POST" enctype="multipart/form-data" action="pic.asp" name="PicForm" target=_self>
虽然这里target=_self
但是window.close仍会打开新窗口,这是showMadolDialog的机制
处理方法是在<BODY>之前加<base target="_self">
3.
这里莫名其妙,如果这样。。。第一次打开文件,就启动上传过程了
dim request2
set request2 = new UpLoadClass
request2.MaxSize =1536000
request2.open()
if request2.form("Command")="Up" then
if request2.form("F1_Err")=0 then
response.write "<script language=""javascript"">"
response.write "window.returnValue='" & request2.form("F1") & "';"
response.write "window.close();"
response.write "</script>"
else
response.write "<br>文件上传时出现错误!<br>"
end if
end if
应该改成
<%
if request("command")="up" then
dim request2
set request2 = new UpLoadClass
request2.MaxSize =1536000
request2.open()
if request2.form("F1_Err")=0 then%>
<script language="javascript">
window.returnValue='<%= request2.form("F1")%>';
window.close();
</script>
<%
else
response.write "<br>文件上传时出现错误!<br>"
end if
end if
%>
Top
15 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-28 22:24:47 得分 0
差不多就是这些,参照着改,good luckTop
16 楼tigerlgf(南湖学士)回复于 2005-01-28 23:54:35 得分 0
谢谢,我试试
Top
17 楼tigerlgf(南湖学士)回复于 2005-01-29 15:50:23 得分 0
问题解决了,是: scoutlin(斥侯) 所提示的前二点错误,感谢!Top
18 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-29 15:51:48 得分 0
不谢哈Top




