您的位置:首页 > 其它

打开新窗口,并且父窗口得到新窗口的返回值,比如论坛头像的选择,对firefox同样适合

2005-09-22 15:06 375 查看
1,如何弹出新窗口?
<script language="javascript">
function OpenImage()
{
window.open("b.aspx","sdf","width=600,height=400,scrollbars=yes");
return false;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<a href="javascript:" onclick="return OpenImage();">打开那个头像页面</a><br>
<asp:Image id="img1" runat="server" ImageUrl="face/167.gif"></asp:Image>
</form>
</body>
</HTML>
注意上面的代码有return,一定要return啊,不然firefox可能会报错误.当然不用showModel....
的原因是firefox不支持,要不方便的多

2,假设父窗口为a.aspx,新窗口为b.aspx,在b.aspx文件中这样 吧
<script language=javascript>
function PI(url)
{
var a = opener.document.getElementById("img1");

a.src = url;

window.close():
}
</script>

好了,现在是b.aspx.cs,他用来遍历face头像目录的所有图片并且显示出来
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
DisplayFace();
}
}

private void DisplayFace()
{
Response.Write("<table cellpadding=0 cellspacing=0 border=0 align='center' width='100%'><tr>");
string appUrl;

//得到应用程序路径
if (Request.ApplicationPath == "/")
appUrl = Request.ApplicationPath;
else
appUrl = Request.ApplicationPath + "/";

//Response.Write(imageFileLocation);
string appPath = HttpContext.Current.Request.PhysicalApplicationPath;//获得应用程序物理路径
string imageFolderPath = appPath + "face";//获得头像目录
string[] filesArray = System.IO.Directory.GetFiles(imageFolderPath,"*");//得到所有的头像图片文件
int i = 0;//用他来做循环,每行输出8个头像图片
foreach(string imageFile in filesArray)
{
string imageFileName = imageFile.Substring(imageFile.LastIndexOf("\\")+1);//取的图片的真实名字,不包含路径
string imageFileLocation = appUrl.Substring(appUrl.LastIndexOf("\\")+1);
//取得头像图片路径
imageFileLocation += "face";
imageFileLocation += "/";
imageFileLocation += imageFileName;
string str = "<td align='center' width='25%'>"+"<a href=javascript:PI('"+imageFileLocation+"')><img border='0' src='"+imageFileLocation+"'></a>"+"</td>";
Response.Write(str);
i++;//每执行一次i加1
if(i%5==0)
{
Response.Write("</tr><tr>");//如果已经是5个头像了,就换行
}
}
Response.Write("</tr></table>");
}

好了,完全好了,现在在ie和tt和firefox下面测试都正常!
只是显示图片的时候有个问题
因为每行5个图片也就是5个单元格,如果最后那行只有4个头像或者三个
就会出现一把X
不知道怎么样解决
如果有朋友知道解决可要告诉我啊

function PI(url)
{
var a = opener.document.getElementById("img1");
var a1 = opener.document.getElementById("txtImage");
a.src = url;
a1.value = url;
window.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐