在 AJAX JSON C# ASPNET 中保存图像时自动关闭 window 浏览器
Automatically close the window browser when the image is saved in AJAX JSON C# ASPNET
在我的 GridView
在 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>
进程运行正常,但我需要在保存图片后自动关闭 window 页面 newpage.aspx
打开的页面
我已经尝试插入另一个按钮来手动关闭 newpage.aspx
,但是 window 没有关闭
在浏览器 IE 11、Edge 和 Chrome 中测试结果没有改变 window 没有关闭
protected void btnclose_Click(object sender, ImageClickEventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
有什么建议吗?
感谢您的帮助。
而不是 server-side 按钮添加 client-side 按钮,这将完成工作
<button type="button" onclick="closeme()">Close me</button>
<script>
function closeme() {
this.window.close();
}
</script>
这会有所帮助
在我的 GridView
在 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>
进程运行正常,但我需要在保存图片后自动关闭 window 页面 newpage.aspx
打开的页面
我已经尝试插入另一个按钮来手动关闭 newpage.aspx
,但是 window 没有关闭
在浏览器 IE 11、Edge 和 Chrome 中测试结果没有改变 window 没有关闭
protected void btnclose_Click(object sender, ImageClickEventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
有什么建议吗?
感谢您的帮助。
而不是 server-side 按钮添加 client-side 按钮,这将完成工作
<button type="button" onclick="closeme()">Close me</button>
<script>
function closeme() {
this.window.close();
}
</script>
这会有所帮助