Sachin
Sachin

Reputation: 5061

issue with window.open in href attribute

I am facing one issue because of URL encoding in window.open function when used under href attribute of link.

Basically I am trying to open a generic popup in my site using window.open function.This popup page accept target page url which will be rendered inside the frame present on popup.aspx

But because of url encoding url parmater which I am passing getting truncated in popup.aspx.cs page.

The same window.open works correctly when directly called from JavaScript function. But failing when embedded in Href attribute.

Below is the Code
Note: input url paramter is a proper decoded url using standard decoding function.

<a href="javascript:void window.open('Popup.aspx?url=%2FB2B%2FDEV%2FSHARE%2FGRID%2FXML_GRID_PAGE.ASP%3FGRIDTYPE%3D2%26SID%3D33172D0A-565A-43D7-8D50-5C223B6E8C24%26CAID%3D0%26ViewID%3DPATIENTPROFILE%26InstanceID%3D375660844%C3%BF14542276%C3%BF3%C3%BFSTANDARD','','scrollbars=yes,menubar=yes,resizable=yes,left=30,top=30,height=500,width=650')"> link</a>

My assumption is when window.open embedded inside the href then somehow its get decoded and then passed to target popup page.

Sample url seen in browser.

https://poorcmcdevvm15.xyz.com//b2b/mainmasterpage/popup.aspx?url=/B2B/DEV/SHARE/GRID/XML_GRID_PAGE.ASP?GRIDTYPE=2&SID=33172D0A-565A-43D7-8D50-5C223B6E8C24&CAID=0&ViewID=PATIENTPROFILE&InstanceID=375660844ÿ14542276ÿ3ÿSTANDARD

when same window.open called through javascript below is the url observed in browser

Popup.aspx?url=%2FB2B%2FDEV%2FSHARE%2FGRID%2FXML_GRID_PAGE.ASP%3FGRIDTYPE%3D2%26SID%3D33172D0A-565A-43D7-8D50-5C223B6E8C24%26CAID%3D0%26ViewID%3DPATIENTPROFILE%26InstanceID%3D375660844ÿ14542276ÿ3ÿSTANDARD

Upvotes: 0

Views: 2936

Answers (2)

Sachin
Sachin

Reputation: 5061

================================================================================ I Solved this problem, very simple fix.Initially I have encoded input url only once using encodeURIComponent function. But in my case decoding happens twice first in href attribute and second time on target dotnet page. So to solve this issue I have encoded input url parameter twice and this solved my problem.

Sample Url after encoded twice using function encodeURIComponent

<a href="javascript:void indow.open('Popup.aspx?url=%252FB2B%252FDEV%252FSHARE%252FGRID%252FXML_GRID_PAGE.ASP%253FGRIDTYPE%253D2%2526SID%253D33172D0A-565A-43D7-8D50-5C223B6E8C24%2526CAID%253D0%2526ViewID%253DPATIENTPROFILE%2526InstanceID%253D375660844%25C3%25BF14542276%25C3%25BF3%25C3%25BFSTANDARD','','scrollbars=yes,menubar=yes,resizable=yes,left=30,top=30,height=500,width=650')"> link2</a>

Upvotes: 1

NoWar
NoWar

Reputation: 37633

It seems that when you generate URL you have to decode it before.

Take a look here

Upvotes: 0

Related Questions