title: Onclick function to open new window and count clicks
body: <p>I have a button on my page to open inserted link in a new tab. To be able to track visit and if visitor clicked that button, I am trying to add variable to onclick function.</p>
  
  <p>Here is my button:</p>
  
  <pre><code>&lt;a href="javascript:void(0);"  onClick="window.open('$link','_blank')"&gt;
  &lt;button type="button" class="btnbuy"&gt;Buy&lt;/button&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Here is what I am trying to do:</p>
  
  <pre><code>&lt;a href="javascript:void(0);"  onClick="myFunction()"&gt;
  &lt;button type="button" class="btnbuy"&gt;Buy&lt;/button&gt;&lt;/a&gt;
  
  &lt;script&gt;
  function myFunction() {
  if(window.open("$link", "_blank")){
  $isclicked = true;
  } }
  &lt;/script&gt;
  
  $sql=mysql_query("INSERT INTO stats (id,isclicked) VALUES ("","$isclicked"");
  </code></pre>
  
  <p>I just wrote this function to show what I am trying to do, so please don't care syntax errors.</p>
  
  <p>Am I on the right way or should I try something else? Thanks for your helps.</p>