我正在升級一個遺留應用程序,它使用煩人的做法,使用Javascript window.open()
打開彈出窗口,以設置值。我有一個問題傳遞查詢字符串變量到該彈出窗口,因爲該網址是建立在服務器端。Javascript window.open()轉義&符
例
JS:
function popupwindow(vLink) {
window.open(vLink, 'Detail','width=600px,height=545px,status=yes,help=no,scrollbars=yes,resizable=yes,top=350');
}
XML
<asp:Label ID="lblOpener" runat="server" Text="_"></asp:Label>
服務器端
int ditem = 123;
string dcode = "ABC";
string vLink = string.Format("detail.aspx?item={0}&code={1}", ditem, dcode);
lblOpener.Attributes.Add("onclick", "popupwindow('" & vLink & "');");
當標籤被點擊我期待彈出與查詢字符串打開:
http://detail.aspx?item=123&code=ABC
相反,我得到的是這樣的: http://detail.aspx?item=123&%3bcode=ABC
我怎樣才能防止這種情況發生?
偉大的解決方案。現在我認爲這是非常有意義的......如果你想爲JavaScript編碼某些東西,你應該用JavaScriptSerializer對它進行序列化。 – tedski