Solved

Javascript window.open problem

Posted on 2011-03-21
5
379 Views
Last Modified: 2012-06-27
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
Comment
Question by:srfreemaninc
  • 3
5 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35186240
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
 
LVL 12

Expert Comment

by:Avinash Zala
ID: 35186754
0
 

Accepted Solution

by:
srfreemaninc earned 0 total points
ID: 35191638
None of those worked.  I ended up created my own str_replace function for the & going to _AMP_
0
 

Author Comment

by:srfreemaninc
ID: 35191667
Thanks for trying guys
0
 

Author Closing Comment

by:srfreemaninc
ID: 35225391
None of the solutions submitted worked, and I had to divise my own solution.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question