2013-11-05 28 views

回答

1

採用json_encode確保了需要被轉義字符轉義。

<script> 
    alert(<?php echo json_encode($msg); ?>); 
</script> 
1
?> 
    <script type="text/javascript"> 
    alert("The error is <?php echo $msg ?>"); 
    history.back(); 
    </script> 
<?php 

或者

echo '<script language="javascript">'; 
echo 'alert(Message here)'; 
echo '</script>'; 
+0

希望此消息沒有「或換行符 – epascarello

+0

一個「不會打破它。 – Waclock

+0

...但帶有「this does not work」的消息 –