Solved

Javascript window.open problem

Posted on 2011-03-21
5
377 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&note=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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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.

708 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

17 Experts available now in Live!

Get 1:1 Help Now