本文介绍了如何在新窗口中打开.pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have the following code
string path = Server.MapPath("\\Reports\\" + DDEP.SelectedValue + ".pdf");
ClientScript.RegisterStartupScript(this.GetType(), "open", "window.open(''"+path+"'',''_blank'' );", true);
I am trying to open the .pdf in a new window
but its opening a blank window.
thanks for the help
我尝试过的事情:
What I have tried:
string path = Server.MapPath("\\Reports\\" + DDEP.SelectedValue + ".pdf");
ClientScript.RegisterStartupScript(this.GetType(), "open", "window.open(''"+path+"'',''_blank'' );", true);
/*
StringBuilder sb = new StringBuilder();
sb.Append("<script type = ''text/javascript''>");
sb.Append("window.open(''");
sb.Append(Server.MapPath("\\Reports\\" + DDEP.SelectedValue + ".pdf"));
sb.Append("'');");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(),
"script", sb.ToString());
*/
推荐答案
<a href="#" onclick="window.open('MyPDF.pdf', '_blank', 'fullscreen=yes'); return false;">MyPDF</a>
按照您的方式,将类似于:
Which, done your way, would be something like:
ClientScript.RegisterStartupScript(this.GetType(), "open", "window.open('"+path+"','_blank', 'fullscreen=yes');", true);
不用担心Google Gods,它们非常友善并给予...
Don''t be afraid of the Google Gods, they are very kind and giving...
string path = ResolveClientUrl("~/Reports/" + DDEP.SelectedValue + ".pdf");
string encodedPath = System.Web.HttpUtility.JavaScriptStringEncode(path, true);
ClientScript.RegisterStartupScript(this.GetType(), "open", "window.open(" + encodedPath + ", ''_blank'');", true);
注意:您需要调用JavaScriptStringEncode
以确保正确编码了任何特殊字符.通过将true
作为第二个参数,可以确保字符串正确加引号,因此您不需要在其周围包括''
字符.
NB: You need to call JavaScriptStringEncode
to ensure that any special characters are properly encoded. By passing true
as the second parameter, you can ensure that the string is properly quoted, so you don''t need to include the ''
characters around it.
这篇关于如何在新窗口中打开.pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!