Reputation: 2565
I want to print some javascript in a php script to open a link in a new window:
<?php
//php script
$link='http://mylink';
print('<script type="text/javascript">');
print('window.open(' . $link . ', "Link","width=600,height=800")');
print('</script>');
?>
But this code didnt work. Any idea how to open a new window with php printed script?
Upvotes: 0
Views: 1205
Reputation: 72967
You're missing some quotes. Replace:
print('window.open(' . $link . ', "Link","width=600,height=800")');
With:
print('window.open("' . $link . '", "Link","width=600,height=800")');
^ ^
In JavaScript, this line will result in:
window.open("http://mylink", "Link","width=600,height=800")
You need the double quotes there to open / close the string.
Upvotes: 3