简体   繁体   中英

How to escape characters in this URL

I have the following code:

onclick='window.open(" ***  ","List","scrollbars=no,resizable=no,width=400,height=280");'

I want to replace the *** with this:

<%# "~/pages/AttchmentViewer.aspx?ID=" + Eval("ID").ToString() %>

but I have problems with the result with the quotation marks:

<a runat="server" id="DocTitleLabel" 

onclick='window.open(\"<%# "~/pages/AttchmentViewer.aspx?ID=" + 
Eval("ID").ToString()  %>" \", "List", "scrollbars=no,resizable=no,width=400,height=280");'>

      <%# Eval("DocTitle") %> 
</a>

Any help!!!

Thanks in advance.

You're escaping the wrong quotation marks, the ones inside the URL need to be escaped not the ones around it.. Also encoding the query-string is a good idea.

So try onclick='window.open("<%# \\"~/pages/AttchmentViewer... instead of onclick='window.open(\\"<%# "~/pages/AttchmentViewer... . (same applies for the closing marks)

Although I wonder what the server-tags (<% %>) will do ...

This should work (tested), but as I told you the ~ must be omitted you just need to give relative path,

onclick='<%# "window.open(\\"~/pages/AttchmentViewer.aspx?ID=" + Eval("Id").ToString() + "\\", \\"List\\",\\"scrollbars=no,resizable=no,width=400,height=280\\");" %>'

您必须对字符串进行urlencode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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