How could click 'if the person enters a link
for fillText
in Canvas ?
Edito: I'm still investigating and I've seen you say that I can associate an event handler to the canvas , then take the text coordinates and if you click the text, l or redirects , but also my problem is that it does not help me to do it for a STATIC TEXT , so what should I do?
With ' clickable ' I mean you can click if it's a URL
, and take you to that URL
by opening another tab.
Investigating I read this, but I still do not know how to do it in practice:
You can detect clicks on the canvas if you add an event handler click on the canvas element and then extract the parameters from mouse position of the event, converts them into local coordinates, check the items that you click and perform any action that be necessary.
var h = document.getElementById("go");
h.addEventListener("click",function() {
var texto = prompt("Ingresa texto a dibujar");
var context = document.getElementById("canvas");
var ctx = context.getContext("2d");
ctx.font = "20px monospace";
ctx.fillText(texto, 20, 60);
ctx.font = "40px monospace";
ctx.fillText("Creando textos..", 70, 30);
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input value="Crear texto" type="button" id="go"/>
<canvas width="1080" height="720" id="canvas"></canvas>
</body>
</html>