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.
Here is my button:
<a href="javascript:void(0);" onClick="window.open('$link','_blank')">
<button type="button" class="btnbuy">Buy</button></a>
Here is what I am trying to do:
<a href="javascript:void(0);" onClick="myFunction()">
<button type="button" class="btnbuy">Buy</button></a>
<script>
function myFunction() {
if(window.open("$link", "_blank")){
$isclicked = true;
} }
</script>
$sql=mysql_query("INSERT INTO stats (id,isclicked) VALUES ("","$isclicked"");
I just wrote this function to show what I am trying to do, so please don't care syntax errors.
Am I on the right way or should I try something else? Thanks for your helps.