문제

I am Trying to escape these darn quotes and stuff in JS. I'm trying to use json_encode. My head hurts from looking at quotes, help???

  $list = '';

    // some loop here

   $message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
   $jscode = 'json_encode('.$message.');return false';
   $list .= '<p> 
        <a href="http://www.example.com/something.php?id=' . $id . '" onclick="' 
              .htmlspecialchars($jscode) . '" >' . $name . '</a></p><br>';

도움이 되었습니까?

해결책

If you want to call json_encode there, you need to do this.

$jscode = json_encode($message).';return false';

You don't even need json_encode for this. You can put this there:

$message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
$jscode = $message.';return false';
$list .= '<p> <a href="http://www.example.com/something.php?id=' . $id . '" onclick="' .htmlspecialchars($jscode) . '" >' . $name . '</a></p><br>';

다른 팁

Try:

$message = 'centeredPopup(this.href,"myWindow","500","300","yes")';
$jscode = json_encode($message);

Otherwise everything else should be OK.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top