如何解决将图像保存在AJAX JSON C#ASPNET中时自动关闭窗口浏览器
在GridView
的{{1}}中,我插入一个按钮来编辑C# ASP.NET 4
的行,以这种方式在浏览器中打开新网页
GridView
在这种模式下,protected void btn1_Click(object sender,EventArgs e)
{
ImageButton btn1 = (ImageButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
int oID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Values[0]);
string queryString = "newpage.aspx?oID=" + oID.ToString();
string newWin = "window.open('" + queryString + "','_blank');";
ClientScript.RegisterStartupScript(this.GetType(),"pop",newWin,true);
}
使用newpage.aspx
和Ajax
将图像保存在服务器上
JSON
该过程正常运行,但是我需要在保存图像后自动关闭打开页面<script type="text/javascript">
$(function () {
$("#btnSave").click(function () {
var image = document.getElementById("cc").toDataURL("image/png");
image = image.replace('data:image/png;base64,','');
var qString = "?" + window.location.href.split("?")[1];
$.ajax({
type: 'POST',url: 'newpage.aspx/oImage' + qString,data: '{ "imageData" : "' + image + '" }',contentType: 'application/json; charset=utf-8',dataType: 'json',success: function (msg) {
alert('Ok');
},failure: function (msg) {
alert(response.d);
},error: function (msg) {
alert(response.d);
},error: function (xhr,ajaxOptions,thrownError) {
alert("error : " + thrownError + JSON.stringify(image));
}
});
});
});
</script>
的窗口
我尝试插入另一个按钮来手动关闭newpage.aspx
,但窗口没有关闭
在浏览器IE 11,Edge和Chrome中进行了测试,结果不会更改窗口不会关闭
newpage.aspx
有什么建议吗?
感谢帮助。
解决方法
代替服务器端按钮,而是添加客户端按钮,
<button type="button" onclick="closeme()">Close me</button>
<script>
function closeme() {
this.window.close();
}
</script>
这会有所帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。