Getting the URL

JeffreyDriver

  • *
  • Posts: 2161
How can I get the current URL that a game is playing on? I'd like the option to perform different actions depending on the URL. Any ideas?
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

mdotedot

  • Posts: 1569
Guessing that you are on HTML5.
The HTML5 Extension has this.

Source:
Code: [Select]
public static function getInfo(info:String):String{
var retval:String="";
#if js
if(info == "TITLE"){
retval=js.Lib.eval("document.title");
}
if(info == "SERVERURL"){
retval=js.Lib.eval("window.location.hostname");
}
#end
return retval;
}// getTitle

So you could also do a code block with just the  js.Lib.eval("window.location.hostname");
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

JeffreyDriver

  • *
  • Posts: 2161
Thanks for this. At the moment I'm still on Flash as HTML5 still isn't fully working for me.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

mdotedot

  • Posts: 1569
When on Flash you can use this:
Code: [Select]
openfl.external.ExternalInterface.call("window.location.hostname")
But the externallinterface.call works only when you have published and run in a browser.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

JeffreyDriver

  • *
  • Posts: 2161
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk