• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Javascript window.open problem

I am having a issue sending an encoded URL to the window.open function.  I'm cant for the life of me figure it out.  I am mainly a PHP coder who uses is comfortable with JS but dont konw all the nuances to be proficient.

I have a function that opens a window with a selected URL
function makeLargeRemote(choice) {
     var chasm = screen.availWidth - 910;
     Remote = window.open(choice,"sub", "width=900,height=700,scrollbars=yes,top=110,left=" + chasm);
     Remote.focus();
}

Open in new window


Pretty simple, I have a link on the page
<a href=javascript:makeLargeRemote('http://www.google.com')>Google!</a>

Open in new window

That link would work fine, and when I pass simple GET varialbes, that works (ie 'fname=John&lname=Doe')

My problem comes when I have a more complicated GET variable (ie 'job=1002&note=Jack%26Jill', equates to Jack&Jill)

If I have that URL code for the ampersand in the link, and pass that to the function, javascript reads that %26 as an & and passes is as such to the browser so the page that opens is 'http://server/page.php?job=1002¬e=Jack&Jill" instead of "page.php?job=1002&note=Jack%26Jill"

I manually enter the correct encoding directly into the function (choice = '/page.php?job=1002&note=Jack%26Jill') it works, but only when I feed URL through the link does it get caught up.

I have tried using PHP to urlencode the link before its sent, but as I said, the function interprets that %26 as an actual &.

I have also tried escape(), but that translates the whole string to URL encoding which also doesnt work.

Please help
0
srfreemaninc
Asked:
srfreemaninc
  • 3
1 Solution
 
sjklein42Commented:
When you escape the GET variable, try turning the & ampersand into %2526 (which has an escaped percent sign) rather than just %26.

That will defer the expanding of the ampersand by two stages rather than just one.
0
 
Avinash ZalaWeb ExpertCommented:
0
 
srfreemanincAuthor Commented:
None of those worked.  I ended up created my own str_replace function for the & going to _AMP_
0
 
srfreemanincAuthor Commented:
Thanks for trying guys
0
 
srfreemanincAuthor Commented:
None of the solutions submitted worked, and I had to divise my own solution.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now