javascript:LaunchApp and php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JZ

    #1

    javascript:LaunchApp and php

    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\mySubD ir";
    echo "<td><a href=\"javascri pt:LaunchApp('$ command')\">bla h</a></td>";

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

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

    echo "<td><a href=\"javascri pt:LaunchApp('m yapp.exe -P \"d:\mydir\m y
    Sub Dir\"')\">blah</a></td>";

    Whatever I tried my string ends after -P

    Regards,
    JZ
  • Ken Robinson

    #2
    Re: javascript:Laun chApp 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\mySubD ir";
    > echo "<td><a[/color]
    href=\"javascri pt:LaunchApp('$ command')\">bla h</a></td>";[color=blue]
    >
    > This works fine. But when 'mySubDir' becomes 'my Sub Dir' myapp
    > requires quotes:
    > myapp.exe -P "d:\mydir\m y Sub Dir"
    >
    > So I tried (along with several variations):
    > echo "<td><a href=\"javascri pt:LaunchApp('m yapp.exe -P "d:\mydir\m y
    > Sub Dir"')\">blah</a></td>";
    >
    > echo "<td><a href=\"javascri pt:LaunchApp('m yapp.exe -P \"d:\mydir\m y
    > Sub Dir\"')\">blah</a></td>";[/color]

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

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

    Ken

    Comment

    • jzgoogle@rogers.com

      #3
      Re: javascript:Laun chApp 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="javascrip t:LaunchApp('.
      "'".$command1." '".
      ')">'."$shortFi leAndRev</a><br>$project </td>";

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

      Comment

      • John Dunlop

        #4
        Re: javascript:Laun chApp and php

        JZ wrote:
        [color=blue]
        > $command="myapp .exe -P d:\mydir\mySubD ir";
        > echo "<td><a href=\"javascri pt:LaunchApp('$ command')\">bla h</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\m y Sub Dir"[/color]

        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.
        [color=blue]
        > So I tried (along with several variations):
        > echo "<td><a href=\"javascri pt:LaunchApp('m yapp.exe -P "d:\mydir\m y
        > Sub Dir"')\">blah</a></td>";
        >
        > echo "<td><a href=\"javascri pt:LaunchApp('m yapp.exe -P \"d:\mydir\m y
        > 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

        Comment

        • jzgoogle@rogers.com

          #5
          Re: javascript:Laun chApp 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

          Comment

          • John Dunlop

            #6
            Re: javascript:Laun chApp 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



            --
            Jock

            Comment

            • jzgoogle@rogers.com

              #7
              Re: javascript:Laun chApp and php

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

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

              echo '<td><a href="javascrip t:LaunchApp('.
              "'".$command1." '".
              ')">'."$shortFi leAndRev</a><br>$project </td>";

              Comment

              • jzgoogle@rogers.com

                #8
                Re: javascript:Laun chApp 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($pr oject).'\\\' -r
                > '.$previousRev. ' -r '.$rev.' '.$shortFile;
                >
                > echo '<td><a href="javascrip t:LaunchApp('.
                > "'".$command1." '".
                > ')">'."$shortFi leAndRev</a><br>$project </td>";[/color]

                Comment

                Working...