Connecting Tech Pros Worldwide Help | Site Map

javascript:LaunchApp and php

JZ
Guest
 
Posts: n/a
#1: Jul 17 '05
I hope there is someone out there that can suggest a solution to my
problem.
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

Regards,
JZ
Ken Robinson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: javascript:LaunchApp and php



JZ wrote:[color=blue]
> I hope there is someone out there that can suggest a solution to my
> problem.
> So here we go:
>
> $command="myapp.exe -P d:\mydir\mySubDir";
> echo "<td><a[/color]
href=\"javascript:LaunchApp('$command')\">blah</a></td>";[color=blue]
>
> 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>";[/color]

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

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

Ken

jzgoogle@rogers.com
Guest
 
Posts: n/a
#3: Jul 17 '05

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.'
'.$shortFile;

echo '<td><a href="javascript:LaunchApp('.
"'".$command1."'".
')">'."$shortFileAndRev</a><br>$project</td>";

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

John Dunlop
Guest
 
Posts: n/a
#4: Jul 17 '05

re: javascript:LaunchApp and php


JZ wrote:
[color=blue]
> $command="myapp.exe -P d:\mydir\mySubDir";
> echo "<td><a href=\"javascript:LaunchApp('$command')\">blah</a></td>";
>
> This works fine.[/color]

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.
[color=blue]
> But when 'mySubDir' becomes 'my Sub Dir' myapp
> requires quotes:
> myapp.exe -P "d:\mydir\my Sub Dir"[/color]

Inside a double-quoted attribute value, a double-quote can
be represented by the entity reference &quot; or the
character references " and &#x22;. Double-quotes are
disallowed in URIs, however, so they must be percent-encoded
with %22.
[color=blue]
> 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[/color]

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!

--
Jock
jzgoogle@rogers.com
Guest
 
Posts: n/a
#5: Jul 17 '05

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.

JZ

John Dunlop
Guest
 
Posts: n/a
#6: Jul 17 '05

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:
[color=blue]
> If there is a better way to invoke my app I would be more than
> happy to hear it.[/color]

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

http://www.jibbering.com/faq/#FAQ4_24

--
Jock
jzgoogle@rogers.com
Guest
 
Posts: n/a
#7: Jul 17 '05

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('.
"'".$command1."'".
')">'."$shortFileAndRev</a><br>$project</td>";

jzgoogle@rogers.com
Guest
 
Posts: n/a
#8: Jul 17 '05

re: javascript:LaunchApp and php


This if funny. My browser doesn't display the solution properly.
So here we go:

jzgoogle@rogers.com wrote:[color=blue]
> 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('.
> "'".$command1."'".
> ')">'."$shortFileAndRev</a><br>$project</td>";[/color]

Closed Thread