Hey peaps. I've just made a new version of my URL query navigation! But im having problems echoing javascipt, my code:

<?php
if($_GET['aid']){
include "folder/" . $_GET['aid'] . ".php";

} else {
   echo '<div align="center">
  <table width="710" border="0" cellpadding="0" cellspacing="0">
    <tr>... etc etc... <a href="javascript:window.external.AddFavorite('http://www.evostation.com/default.php', 'ES - EvoStation.com'">....(more HTML)....';
}
?>

See the problem with the quotes in the JS? is there a work-around on this? Maybe I could use the <script src> method? what do u guys think? Thx.

    Couldn't you just use \" whereever quotes occur in your string? I think that would work.

      Use backslash when using simplequotes inside your echo

      Cant show you how because this parses the backslashes off the post when I try to use em.

        It can be a pain to nest quotes inside of quotes. One work around is to break up the string using the dot operator

        echo
        '<div align="center">
        <a href="' .
        "java script:window.external.AddFavorite('http://www.evostation.com/default.php', 'ES - EvoStation.com'" .
        '">content</href>';

        The other thing you could do is to use "" around the complete echo string and then use \" for all of the " inside of the string.

          It doesnt matter lol. It's working now... thats the main thing! One more question... That AddFavorite function is for IE, it wouldnt work for NN! Is there an NN version of "adding to favorites"?

            Although you have already got this working, I'm gonna post my opinion anyway for anyone else who is looking at this.

            Whenever I use javascript inside my PHP i do it like this:

            <?php
            // some PHP code
            
            $if ($blah == "hello") {
               ?>
               <script>
                  // My javascript
                  alert("Hello. This is Matt's Javascript.")
               </script>
               <?php
            }
            ?>
            

            It doesnt hav 2 be in an if statement obviously but i put it there cos i felt like it 🙂

            Its easier to do it outside the PHP simply coz u dont hav 2 do any extra \'s 🙂

            for example, if this is a line of javascript:

            alert("Matt says \"hi there\".");
            

            then in php it would b like this:

            echo "alert(\\"Matt says \\\\\\"hi there\\\\\\".\\");";
            

            And that looks confuzing (i proly wrote it wrong anyways 🙂)

            Hope this helps - its just my opinion 🙂

              Write a Reply...