Solved

Javascript window.open problem

Posted on 2011-03-21
5
378 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now