I'm writing mostly in PHP, but one function requires me to use JavaScript. I need to access a PHP variable in my JavaScript. I've placed the following code between the <head>
tags:
<script>
$(document).ready(function(){
$(document).keyup(function(e) {
if ($('.pho_big').is(':visible') && e.keyCode==27) {
var js_link = '<?php echo $p_link; ?>';
window.location.href = js_link;
}
});
});
</script>
In short, when the esc key is pressed, I want to go to $p_link
. So I'm trying to copy $p_link
to js_link and go there. Instead of getting the contents of $p_link
, my browser is trying to go to <?php%20echo($p_link)%20?>
, which is obviously incorrect.
I've already gone here, here, and here, all of which seem to tell me to do exactly what I'm doing. My knowledge of JavaScript is near zero, so I'm probably missing something simple, but I don't know enough to know what or troubleshoot.