0

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?

1
  • Don't look at PHP and say that the JavaScript doesn't work. Look at the JavaScript source code in the browser and figure out why /that/ doesn't work. Commented Jul 16, 2014 at 13:51

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

works could you only please add the $ sign so the answer will be correct
Yeap, got it, @user3714829 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.