简体   繁体   English

重定向到新选项卡中的页面时,请避免使用弹出窗口阻止程序

[英]Avoid Pop-up blocker when redirecting to a page in a new tab

So, I have an a application that needs a report to be exported in PDF. 所以,我有一个需要以PDF格式导出报告的应用程序。 And on button click the generated pdf should open in a new tab for the user to view the contents before downloading. 然后在按钮上单击生成的pdf应在新选项卡中打开,供用户在下载前查看内容。

My problem is opening the page in a new tab gets a pop-up blocker warning, I already tried the following: 我的问题是在新选项卡中打开页面获取弹出窗口阻止程序警告,我已经尝试过以下操作:

string url = "/Page2.aspx?id="+id+;

Response.Write("<script>");
Response.Write("window.open('"+url+"','_newtab')");
Response.Write("</script>");

....... .......

Page.ClientScript.RegisterStartupScript(this.GetType(),"OpenWindow","window.open('"+url+"','_newtab');",true);

... ...

ScriptManager.RegisterStartupScript(this, this.GetType(), "NewTab", "window.open('" +url+ "');", true);

and still no progress. 仍然没有进展。 The redirecting should be done in the server side since I've got to get some data and passed it together with the link. 重定向应该在服务器端完成,因为我必须获取一些数据并将其与链接一起传递。

Usually a browser will block a popup unless the popup is initiated by the user. 除非弹出窗口是由用户启动的,否则浏览器通常会阻止弹出窗口。

If a window opens directly as a result of an onclick it will generally open okay. 如果一个窗口由于onclick直接打开,它通常会打开。 If the button click indirectly opens the window, it is more likely to be blocked. 如果按钮单击间接打开窗口,则更有可能被阻止。 So your injecting a script tag etc. is likely to be blocked as a webpage being spammy (no-one wants unsolicited popups to appear when they browse). 因此,您注入脚本标记等可能会被阻止,因为网页是垃圾邮件(没有人希望在浏览时出现未经请求的弹出窗口)。

Putting the window.open directly into the onclick event is the most likely solution to work. 将window.open直接放入onclick事件是最有可能的解决方案。

Ultimately however you cannot control the behaviour of the browser though so it may not be possible to do what you want. 但最终你无法控制浏览器的行为,因此可能无法做你想做的事情。

Changing the button into a styled hyperlink would work (with a target of _blank or similar). 将按钮更改为样式化超链接将起作用(目标为_blank或类似)。 It is not possible to tell a browser to open in a new tab vs a new window. 无法告诉浏览器在新选项卡中打开新窗口。

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

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