Vithar Posted October 7, 2014 Share Posted October 7, 2014 Hi, I am looking to embed a hyperlink in my game, so that if you click it, you will be taken to a new webpage, or open the page in a new window. Is this possible? If so, where would I start? Link to comment Share on other sites More sharing options...
lewster32 Posted October 8, 2014 Share Posted October 8, 2014 Something like this:button = game.add.button(game.world.centerX, game.world.centerY, 'button', function() { // open in the same window (like clicking a link) window.location.href = "http://www.google.com"; // open in a new window instead (this will likely be blocked by popup blockers though) // window.open("http://www.google.com", "_blank");}, this); Link to comment Share on other sites More sharing options...
Vithar Posted October 14, 2014 Author Share Posted October 14, 2014 Thanks, exactly what I was looking for! Link to comment Share on other sites More sharing options...
vohogames Posted October 7, 2015 Share Posted October 7, 2015 I did in this way, it seems to work but i am not sure if its the way to do.added working version :http://www.oyuntt.com/hayvan-bulmaca-hayvanciklari-kurtar/oyna/create: function () {if (this.game.device.desktop || this.game.device.android ) {var gp = this.add.button(0, this.game.height- this.game.height / 3 , 'googleplayimg', this.openga, this, 1, 0);gp.anchor.setTo(0, 0.5);}}openga : function(){if (this.game.device.desktop ) {window.open("https://play.google.com/store/apps/details?id=com.vohogames.animalpuzzle", "_blank");}else{window.open("market://details?id=com.vohogames.animalpuzzle","_blank");}} Link to comment Share on other sites More sharing options...
megmut Posted October 7, 2015 Share Posted October 7, 2015 Just a side note, if your canvas is embedded inside an Iframe, then window.location will now work. In order to get around this, you may use top.location.href = 'somepage. Link to comment Share on other sites More sharing options...
craidencool Posted July 11, 2016 Share Posted July 11, 2016 how do you close window.location.href = "http://www.google.com"; and go back to the game? assuming I have a button to go back to the game on the google page opened. Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2016 Share Posted July 11, 2016 No, unfortunately not - this is a feature some mobile devices provide to go back to an app from another app, but since this is a link, all you have is the browser's back button. You may instead wish to open the link in a new window/tab, which preserves the state of your game. Link to comment Share on other sites More sharing options...
mattstyles Posted July 11, 2016 Share Posted July 11, 2016 If your game permits it, you could save the state of the game before changing window location and then reload the game when/if the user returns. You may be doing this already. You'd probably do this via local storage of some sort and then reload the game from server (if necessary) based on those local stored variables. Given that you have control over the url you could also use query parameters to have some control over the users' actions i.e. in pseudo-code // Generate secret key, related to saved game state // Pass secret key to external link // http://externallink.com?KEY=xxx // Use query param in embedded link so that // http://yourgame.com?KEY=xxx // Use query param in game to load the state associated with the key Of course, you can't force anyone to come back to your game, might be a better solution to host the page in an iframe inside your game, that way you have a course for dialogue using emitters between parent and child windows, similar to websocket or web worker dialogue. Link to comment Share on other sites More sharing options...
Recommended Posts