简体   繁体   English

从后面的代码打开弹出窗口

[英]Opening popup window from code behind

I am new to asp.net and hence stuck at a very simple point.我是 asp.net 的新手,因此陷入了一个非常简单的问题。 I am trying to open a popup window from an existing browser window using below code :我正在尝试使用以下代码从现有浏览器窗口打开一个弹出窗口:

string url = "D13.aspx";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);

D13.aspx is an empty aspx page. D13.aspx 是一个空的 aspx 页面。 There are no console errors or popup getting blocked.没有控制台错误或弹出窗口被阻止。 But the popup window is not opening up.但是弹出窗口没有打开。 Is there anything to be done in javscript or this code alone is enough?有什么可以在 javscript 中完成的,还是仅此代码就足够了? Any suggestions?有什么建议?

I have tested the below and found that it works (IE 11):我已经测试了以下内容并发现它有效(IE 11):

protected void OpenPopUp_Click(object sender, EventArgs e)
{
    string url = "D13.aspx";
    string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
    ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
}

Markup:标记:

<asp:Button Text="Open PopUp" OnClick="OpenPopUp_Click" runat="server" />

By default your browser blocks pop-up enable popup in your browser then run it, will work fine.. I have checked it with chrome.默认情况下,您的浏览器会阻止弹出窗口,在浏览器中启用弹出窗口,然后运行它,会正常工作.. 我已经用 chrome 进行了检查。 you your chrome is blocking that at right hand side of window corner there will be a red alert showing that popup blocked you can allow from there...你的 chrome 阻止了在窗口角落的右侧会有一个红色警报,显示弹出窗口被阻止,你可以从那里允许......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM