javascript:LaunchApp and php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I hope there is someone out there that can suggest a solution to my
So here we go:

$command="myapp.exe -P d:\mydir\mySubDir";
echo "<td><a href=\"javascript:LaunchApp('$command')\">blah</a></td>";

This works fine. But when 'mySubDir' becomes 'my Sub Dir' myapp
requires quotes:
myapp.exe -P "d:\mydir\my Sub Dir"

So I tried (along with several variations):
echo "<td><a href=\"javascript:LaunchApp('myapp.exe -P "d:\mydir\my
Sub Dir"')\">blah</a></td>";

echo "<td><a href=\"javascript:LaunchApp('myapp.exe -P \"d:\mydir\my
Sub Dir\"')\">blah</a></td>";

Whatever I tried my string ends after -P


Re: javascript:LaunchApp and php

JZ wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it

Did you try:
$command = 'myapp.exe -P "d:\mydir\my Sub Dir"';
echo '<td><a href="javascript:LaunchApp(' . "'" . $command . "'" .

You can also try:
$command = 'myapp.exe -P d:\mydir\' . urlencode('my Sub Dir');


Re: javascript:LaunchApp and php

I tried the following:
[$project is the directory from my example]

$command1='si diff -g -P "'.$project.'" -r '.$previousRev.' -r '.$rev.'

  echo '<td><a href="javascript:LaunchApp('.

All I see is:
javascript:LaunchApp('si diff -g -P

Re: javascript:LaunchApp and php

JZ wrote:

Quoted text here. Click to load it

Only for a bizarre definition of 'fine'.  It might give the
impression of working in a handful of situations, but it
fails in a bucketload and it's by no means correct.

Strictly speaking, the resulting construct is not HTML
because, on two accounts, the href value is not a URI.  
First, the value contains characters which are disallowed in
URIs:  spaces and backslashes, the percent-encodings of
which are %20 and %5C respectively.  Second, the javascript
scheme has not been registered, and so even if you were to
percent-encode the disallowed characters, the construct
would still violate the HTML spec.

See c.i.w.a.html for discussions on the more practical
downsides of the javascript pseudo-protocol in hrefs, and on
why you should use event handlers instead.

Quoted text here. Click to load it

Inside a double-quoted attribute value, a double-quote can
be represented by the entity reference &quot; or the
character references &#34; and &#x22;.  Double-quotes are
disallowed in URIs, however, so they must be percent-encoded
with %22.

Quoted text here. Click to load it

In the first example, yes; you get a parse error because the
double-quote after the '-P' ends the first string of the
echo.  For a double-quote to appear in a double-quoted
string, you must escape it with a backslash.

If you look closely, you'll see the string in the second
example is exactly what you asked for:  The escaped double-
quote after the '-P' closes the href attribute, and by dint
of reasonable error recovery, everything up to the
next '>' is ignored.  Proof:  View the source.

Reasonableness isn't a requirement of the spec however.

Slainte! & HAGW!


Re: javascript:LaunchApp and php

I agree that what I am trying to do could be flawed. After all
sometimes we need to do what is not exactly our area of expertise. I
don't know much about php or html but I need to fix this bug. If there
is a better way to invoke my app I would be more than happy to hear it.


Re: javascript:LaunchApp and php

To followup-to an article using G2, go to 'show options' and
*then* 'reply', interleaving your comments below those to
which you are responding and deleting superfluous text.  
Please do not just 'reply'.

[Anonymous -- J.D.] wrote:

Quoted text here. Click to load it

Sorry, I don't know what you're trying to do.  'Invoke my
app' doesn't mean much to me.

However, if you're trying to call a Javascript function, the
recommended way is through the intrinsic events, not the
href.  See


Re: javascript:LaunchApp and php

For what is worth here is my solution to my problem:

$command1='si diff -g -P \\''.ltrim($project).'\\' -r
'.$previousRev.' -r '.$rev.' '.$shortFile;

echo '<td><a href="javascript:LaunchApp('.

Re: javascript:LaunchApp and php

This if funny. My browser doesn't display the solution properly.
So here we go: wrote:
Quoted text here. Click to load it

Site Timeline