Javascript window.open无法在代码后面工作

时间:2022-10-22 15:03:09

I have a menu user control inside my master page. After login, menu will be populated. When the Print Receipt Menu is clicked, it will open a Receipt in another window. i try with the below code but it seems not working from code behind. It works if i put into html instead of code behind.

我的母版页面中有一个菜单用户控件。登录后,将填充菜单。单击“打印收据”菜单时,将在另一个窗口中打开“收据”。我尝试使用下面的代码,但它似乎无法从代码背后。如果我放入html代替后面的代码,它的工作原理。

Dim sOnClick as string = "onclick='javascript:window.open('http://localhost:10101/Project/Sales/PrintReceipt.aspx?id=12345', '_blank','width=420,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=No');'" 

Dim sbMenu As New StringBuilder
sbMenu.Insert(0, "<li><a href='#' " & sOnClick & ">Print Receipt</a></li>") 

2 个解决方案

#1


0  

To call you java script function code behind do like this

要调用你后面的java脚本函数代码就像这样

Page.ClientScript.RegisterStartupScript(this.GetType(), "AKey", "YOUR JAVA SCRIPT FUNCTION", true);

Page.ClientScript.RegisterStartupScript(this.GetType(),“AKey”,“你的JAVA SCRIPT FUNCTION”,真);

#2


0  

Try using response stream instead:

请尝试使用响应流:

Response.Write("<script>");
Response.Write("window.open('https://www.google.com','_blank')");
Response.Write("</script>");

You can also use the below for your <a> tag:

你也可以使用下面的标签:

Target= "_blank"

#1


0  

To call you java script function code behind do like this

要调用你后面的java脚本函数代码就像这样

Page.ClientScript.RegisterStartupScript(this.GetType(), "AKey", "YOUR JAVA SCRIPT FUNCTION", true);

Page.ClientScript.RegisterStartupScript(this.GetType(),“AKey”,“你的JAVA SCRIPT FUNCTION”,真);

#2


0  

Try using response stream instead:

请尝试使用响应流:

Response.Write("<script>");
Response.Write("window.open('https://www.google.com','_blank')");
Response.Write("</script>");

You can also use the below for your <a> tag:

你也可以使用下面的标签:

Target= "_blank"