[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

javascript: problem in window.open with URL wich contains quote/apostrophe

Hi, I've got problem with URL containing apostrophe (quote)

tried different ways but no one is working....

the following code is in PHP and javascript

the problem is that when $tabCol2[0] variable contains quote it does not open anything.....

thanks for your help.
function openwindow(arg1,arg2,arg3)
{
	window.open(arg1,arg2,arg3);
}



<a  href="javascript:openwindow('<?echo"modifier/enduser.php?type=enduser&pDevis=$pDevis&tmp=1&pEnd_user=$pEnduser&oldEndUser=".urlencode("$tabCol2[0] (CT:$pEnduser)");?>','','toolbar=no,resize=yes,location=no,directories=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,width=1000,height=300,top=50,left=50')" >zzzzzzzzzz</a>

Open in new window

0
bruno_boccara
Asked:
bruno_boccara
2 Solutions
 
Kim WalkerWeb Programmer/TechnicianCommented:
Try escaping the quote with a backslash (\").
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Sorry, I don't think that'll work. Try using the character entity &quot;
0
 
Ray PaseurCommented:
You might want the PHP function urlencode()
http://us3.php.net/manual/en/function.urlencode.php
0
Industry Leaders: 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!

 
leakim971PluritechnicianCommented:
try this :


<a  href="javascript:openwindow('<?echo"modifier/enduser.php?type=enduser&pDevis=$pDevis&tmp=1&pEnd_user=$pEnduser&oldEndUser='+encodeURIComponent(\"". addslashes($tabCol2[0] (CT:$pEnduser)) . "\"));?>','','toolbar=no,resize=yes,location=no,directories=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,width=1000,height=300,top=50,left=50')" >zzzzzzzzzz</a>

Open in new window

0
 
bruno_boccaraAuthor Commented:
no one of these solution are working.....
getting crazy.
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Try letting javascript encode the uri.
function openwindow(arg1,arg2,arg3)
{
        window.open(encodeURI(arg1),arg2,arg3);
}

Open in new window


You can also try converting the quote to character entities in PHP.
htmlspecialchars(urlencode("$tabCol2[0] (CT:$pEnduser)"),ENT_QUOTES)

Open in new window


If that doesn't work, can you expound on the problem? Does a blank window open? Does a window open at all? Are the query string values corrupted when it gets to the PHP processor? Is a javascript error being invoked? What version of PHP are you using?

Can you post an example?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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