0

Easeljs - Hyperlinking.

Out of an easeljs script: how can I hyperlink to another web site? For instance: when an onClickEvent occurs another window would open - in my case I want to send a variable, an ID to another page with an SQL request on the ID for more details.

Any sample would be great.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
J o e
  • 11
  • 3

3 Answers3

1

enter image description here

When you click on the red shape it will open google.com. You can add the hyperlink any easeljs object like this.

    <!DOCTYPE HTML>
<html>
<head>
<title></title>

<style>
    #myCanvas{
        background-color:#CCC;
    }
</style>

<script src="easeljs-0.7.1.min.js"></script>
<script src="jquery-1.7.2.min.js"></script>
<script>
var canvas, stage;
$().ready(function(e) {
    canvas = document.getElementById("myCanvas");
    stage = new createjs.Stage(canvas);
    var shape = new createjs.Shape();
    shape.graphics.beginFill("#ff0000").drawRect(0, 0, 100, 100);
    stage.addChild(shape);
    shape.x = 200, shape.y = 100;
    shape.addEventListener("click", goURL, false);
    stage.update();

});
function goURL(){
    window.open("http://google.com");
    }
</script>


</head>
<body onload="init()">
<canvas id="myCanvas" width="500" height="400">

</canvas>
</body>
</html>
codersaif
  • 946
  • 9
  • 15
0

http://www.w3schools.com/jsref/met_win_open.asp

window.open(URL,name,specs,replace);

But be aware that popups/new tabs like this might be blocked by the browser if not followed an user-event. You could also retrieve the details via jQuery.get or jQuery.ajax ect.. and then display the information directly in your application.

olsn
  • 16,644
  • 6
  • 59
  • 65
0

You can also use window.location in case you only want to redirect to another page instead of open a new window/tab. For example:

var id = 0 //the variable you want to pass;

shape.addEventListener("click", gotoURL);

function gotoURL(){
  location.assign( 'http://yoursite.com/search?id='+id );
}