如何在 C# ASP.NET 中通过按钮单击事件打开新的浏览器窗口?
请分享任何示例。
我正在执行以下代码。请让我知道哪里出错了。
btn_Click()
{
if(condition==true)
{
this.Page.ClientScript.RegisterStartupScript(
this.GetType(),
"page_index_script2",
"openNewWindow();",
true
);
}
}
JavaScript 函数是
function openNewWindow()
{
alert('HI');
window.open('http://www.stackoverflow.com');
}
当我从 javascript 函数 Alert 运行代码时,新窗口没有打开。
最佳答案
你可以使用这样的代码,你可以根据需要调整高度和宽度
protected void button_Click(object sender, EventArgs e)
{
// open a pop up window at the center of the page.
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'your_page.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
}
关于c# - 如何在按钮单击事件上打开新的浏览器窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9056103/