Javascript opener.location question

i’m using a PHP script that calls a variable out of a MySQL database, and puts it an “a href” javascript opener.location.

basically i call a variable $var and do this

<a href=“javascript:;” onclick=opener.location=“mypage.php?id=$var”>$var

now the problem i’m having is some of my $var variables have whitespace. they get displayed correctly in my window, but the link doesn’t work.

my link will look like “this has white space” which shows that the $var is coming out correctly, but the link doesn’t work?!?!? it works fine with $var without whitespace, so i don’t know what to do. thanks for any help in advance

If I understood correctly the problem…
You must convert whitespace to . In this way the browser will be able to request it and the server to understand the request.

URIs should not have whitespace in them at all. You have to encode the data first.

You need to use this function:

So you probably want something like:

$var = "this has white space"; $escape_var = urlencode($var); echo "<a href=\"javascript:;\" onclick=opener.location=\"mypage.php?id=$escape_var\">$var</a>";
Though perhaps to avoid headaches you should follow their advice and do:

$var = "this has white space"; $encode_var = urlencode($var); $html_var = htmlentities($var); $uri = "mypage.php?id=$encode_var"; $html_uri = htmlentities($uri); echo "<a href=\"javascript:;\" onclick=opener.location=\"$html_uri\">$html_var</a>";
:cool: Perl / MySQL / HTML CSS

thanks so much! the urlencode worked like a champ!

But why are you using that messy JavaScript in the first place, instead of Keeping It Simple, Stupid by merely putting the destination address in the HREF attribute value, so that it works for users with or without scripting enabled?

– Dan

because the link is in a pop-up, and it changes the parent window beneath it. as far as i know there is no way to do this using HTML only.