Put a link inside a canvas

2

with PHP and through an SQL query, I get some parameters, which I show through a for and that end up showing up as a link. This is easy to implement and it works, but I want that link to be inside an HTML canvas and this is where the problems appear, because, if I put the link in a PHP variable and then I pass it to a Javascript variable that then I put in the canvas as text, what it does is show me the link as text with all the HTML code. I say there must be a simpler way to do it.

Something like what I'm going to say next:

function crearcanvas(enlace) {
  var link = enlace;
  var canvas = document.getElementById("canvas");
  canvas.fillStyle = '#CCCC00'; 
	canvas.font = "sans-serif";
	canvas.fillStyle = "black";
	canvas.fillText(enlace,45,75);
  ....
  ....
}
<php
  $tabla = tabla();
    foreach ($db->query($tabla) as $row) { 
      $valor1 = $row['valor1'];
      $valor2 = $row['valor2'];
      $valor3 = $row['valor3'];
      $enlace = "<a href='pagina.php?valor1=".$valor1."&valor2=".$valor2."'>".$valor3."</a>";
?>
      <canvas id="canvas"></canvas>
      <script>
        var enlace = <?php echo $enlace; ?>;
        crearcanvas(enlace);
      </script>
<?php
  }
?>

One thing, I'm not looking to create a button or an animation, I just want to put a simple link inside the canvas.

    
asked by Isaac Palacio 16.03.2018 в 23:27
source

1 answer

1

To put a link on a canvas, you have to draw it yourself and respond to the click event.

It's easier to overlap a div above:

<div style='position: relative;'>
    	<canvas id="canvas" width="l00" height="100" style="position: absolute; left:0; border: 1px solid black;">Canvas no soportado.</canvas>
    	<div style='position: absolute; left: 5px; top: 5px;'><a href='http://www.stackoverflow.com'>Enlace</a> </div>
    	</div>
    
answered by 17.03.2018 / 21:04
source