如何在window.open中编写查询字符串 [英] how to write query string in window.open

查看:103
本文介绍了如何在window.open中编写查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在这里,iam将在window.opn脚本中传递querystring,但是它得到语法错误.

Iam编写了这样的代码:

Dear friends,

Here iam going to pass querystring in window.opn script but its getting syntax error.

Iam written a code like this:

Response.Write("<script> window.open(ViewDocuments.aspx?id="+ e.CommandArgument.ToString()")</script>"));



但其显示的语法错误,请进行修改.让我知道我在哪里做错误.


问候,


AnilKumar.D



But its showing syntax error please Modify this.let me know where iam doing mistake.


Regards,


AnilKumar.D

推荐答案



试试这个:

Hi,

Try this:

Response.Write("<script> window.open(ViewDocuments.aspx?id='"+ e.CommandArgument.ToString()+"')</script>");



但这不是最佳实践.尝试以下最佳做法:



But this is not best practice. Try this for best practice:

string script = "window.open('popupPage.aspx'"+e.CommandArgument.ToString()+"'', 'myPopup')";
 ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script, true);




祝一切顺利.
--Amit




All the best.
--Amit


第一个选项是验证e.CommandArgument的内容.

第二种选择:如果内容格式正确,则潜在的问题可能在web.config中.实际上,对于web.config的全球化,responseEncoding应该为"ISO-8859-15". web.config的字符串应为:
First option is to validate the content of e.CommandArgument.

Second option: If the content is in good format, then the potential problem might be in web.config. In fact, globalization of web.config, the responseEncoding should be "ISO-8859-15". The string of web.config should be:
<globalization fileencoding="ISO-8859-15" requestencoding="ISO-8859-15" responseencoding="ISO-8859-15" culture="auto" uiculture="auto" />


尝试:
// Assuming that the URL formed is correct. 
// Sure that no resolving of URL for ViewDocuments.aspx needed?
string myURL = "ViewDocuments.aspx?id="+ e.CommandArgument.ToString();
Response.Write("<script> windows.open(" + myURL + ");</script>");


好像您错过了实现中的右括号.


更新:
以防万一,如果您的ViewDocuments.aspx链接需要正确的URL,请使用ResolveURL方法获取正确的重定向URL,然后使用相同的URL.


Looked like you missed closing bracket in your implementation.


UPDATE:
Just in case, if your ViewDocuments.aspx link needs correct URL, use ResolveURL method to get the correct redirect URL and then use the same.


这篇关于如何在window.open中编写查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆