Solved

Javascript window.open problem

Posted on 2011-03-21
5
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

688 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