以下是html代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>11</title>
<script type="text/javascript" language="javascript">
function getif(txt1)
{
var txt = document.getElementById("txt_1");
txt.value = txt1;
}
</script>
</head>
<body>
<iframe style="display:block;" name="hideframe" id="testframe"></iframe>
<div id = "nofri">
<form id = "imageform" method ="post" action= "asp/upload.ashx" enctype ="multipart/form-data" target= "hideframe">
<input type="submit" value="上传"/>
<input type="file" name="file" />
<input type="text" id="txt_1" />
<input type="button" id="btn_1" onclick = "getif()" value = "取值"/>
</form>
</div>
</body>
</html>以下是提交到得一般处理程序,用C#编写<%@ WebHandler Language="C#" Class="upload" %>using System;
using System.Web;
using System.IO;
using System.Net;
public class upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
context.Response.ContentType = "utf-8";
HttpPostedFile file = context.Request.Files["file"];
string newFilename = Guid.NewGuid().ToString();
var extension = Path.GetExtension(file.FileName).ToUpper();
newFilename += extension;
string filepath = string.Empty;
if (SaveAsImg(newFilename, file, context))
{
//context.Response.Write("<div id='tframe'>" + newFilename + "</div>");
context.Response.Write("<script>parent.getif('" + newFilename + "')</script>");
}
else
{
context.Response.Write("false");
}
} public bool SaveAsImg(string filename, HttpPostedFile file, HttpContext context)
{
HttpServerUtility server = context.Server;
try
{
string filepath = server.MapPath("~/img/userimg/" + filename);
file.SaveAs(filepath);
return true;
}
catch
{
return false;
}
}
public bool IsReusable {
get {
return false;
}
}}问题是,在chrome、FF等内核的浏览器下,该段代码都能达到预期效果。从upload.ashx中取得文件名。
但ie下,iframe直接将返回的代码显示<script>parent.getif('" + newFilename + "')</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>11</title>
<script type="text/javascript" language="javascript">
function getif(txt1)
{
var txt = document.getElementById("txt_1");
txt.value = txt1;
}
</script>
</head>
<body>
<iframe style="display:block;" name="hideframe" id="testframe"></iframe>
<div id = "nofri">
<form id = "imageform" method ="post" action= "asp/upload.ashx" enctype ="multipart/form-data" target= "hideframe">
<input type="submit" value="上传"/>
<input type="file" name="file" />
<input type="text" id="txt_1" />
<input type="button" id="btn_1" onclick = "getif()" value = "取值"/>
</form>
</div>
</body>
</html>以下是提交到得一般处理程序,用C#编写<%@ WebHandler Language="C#" Class="upload" %>using System;
using System.Web;
using System.IO;
using System.Net;
public class upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
context.Response.ContentType = "utf-8";
HttpPostedFile file = context.Request.Files["file"];
string newFilename = Guid.NewGuid().ToString();
var extension = Path.GetExtension(file.FileName).ToUpper();
newFilename += extension;
string filepath = string.Empty;
if (SaveAsImg(newFilename, file, context))
{
//context.Response.Write("<div id='tframe'>" + newFilename + "</div>");
context.Response.Write("<script>parent.getif('" + newFilename + "')</script>");
}
else
{
context.Response.Write("false");
}
} public bool SaveAsImg(string filename, HttpPostedFile file, HttpContext context)
{
HttpServerUtility server = context.Server;
try
{
string filepath = server.MapPath("~/img/userimg/" + filename);
file.SaveAs(filepath);
return true;
}
catch
{
return false;
}
}
public bool IsReusable {
get {
return false;
}
}}问题是,在chrome、FF等内核的浏览器下,该段代码都能达到预期效果。从upload.ashx中取得文件名。
但ie下,iframe直接将返回的代码显示<script>parent.getif('" + newFilename + "')</script>
解决方案 »
- DataSet问题
- 为什么注释掉这句话,效果还是一样的,那放着干嘛?
- 用户代码未处理sqlException
- 如何在RowCommand事件中找模板中的控件?我在模板列中有一个Lable控件,我想在RowCommand中找到这个控件?或者我在RowCommand中把每行的索引值取到也行?
- ☆☆☆owc11组件怎样让饼图实现3D效果?百分比怎么才能显示在饼图外面?
- javascript中的函数再怎么调用CS文件中的函数啊
- GridView控件分页页脚不能显示?
- 求解答
- 急求一个asp.net论坛
- []求助] CSS设置无效,label不能靠右[充QQ会员]
- 谁研究过ActiveReports6,怎么加封面和封底
- 今天发现一个网站的js文件下载不了,IE临时文件中也没有,用的啥技术?
=====================>
context.Response.ContentEncoding = System.Text.Encoding.UTF8;