user3111518
user3111518

Reputation: 35

Javascript window.open() with php code

<?php
    $data=SOME_STRING;
    $url="http://SOME_WEBSITE.com/".$data; //$url is a valid website with the addition of data
?>
<input type="button" value="button" onClick="window.open(<?php echo $url;?>)" >

But nothing happens when I click on the button.

It does work when I replace the PHP echo with the precise url string but I want to be able to pass different urls.

  1. Why doesn't it work?
  2. Can you please think about alternative way to achieve this?

Upvotes: 0

Views: 2305

Answers (1)

xdazz
xdazz

Reputation: 160973

You need quotes:

<input type="button" value="button" onClick="window.open('<?php echo $url;?>')" />

Upvotes: 4

Related Questions