Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Get URL of HTML build
Started by horacebury Feb 12 2019 01:36 AM

7 replies to this topic
web html html5 build url

Best Answer XeduR @Spyric , 12 February 2019 - 02:10 AM

It should be quite easy.

Since you can use JavaScript in HTML5 builds ( https://docs.coronalabs.com/guide/html5/plugins/index.html ), you can just use this simple JS function to get the URL ( https://www.w3schools.com/js/js_window_location.asp ).

I'm curious as to what you are planning to use this on? To see what sites your game is running on and how popular they are there? Or are you perhaps thinking of implementing some DRM system to block the game from running on sites that are not specifically approved? Or something completely different perhaps? :D

 

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

Is it possible to get the URL of a web build in Lua?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 616 posts
  • Corona SDK

  Best Answer

It should be quite easy.

Since you can use JavaScript in HTML5 builds ( https://docs.coronalabs.com/guide/html5/plugins/index.html ), you can just use this simple JS function to get the URL ( https://www.w3schools.com/js/js_window_location.asp ).

I'm curious as to what you are planning to use this on? To see what sites your game is running on and how popular they are there? Or are you perhaps thinking of implementing some DRM system to block the game from running on sites that are not specifically approved? Or something completely different perhaps? :D

 


  • horacebury likes this

[TOPIC: post.html]
#3

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

The latter, but not in anger.



[TOPIC: post.html]
#4

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

@spyric Have you tried the code in the docs vs the code in the github example repo? I’m having trouble getting the code from the docs working and the repo is a lot more involved.

[TOPIC: post.html]
#5

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

Scratch that - got it working by stripping down the CoronaLabs github demo:

 

https://github.com/HoraceBury/CoronaJsToLua


  • XeduR @Spyric likes this

[TOPIC: post.html]
#6

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 616 posts
  • Corona SDK

Seems like I'm a bit late, but I'm glad to hear you got it working!

If you are planning on providing the ready project to some external parties, you may also want to consider cleaning up the string once you have it. For instance, you could search the string for "://www." or "://" and the domain type, i.e. ".io", ".com", etc. and then use their values to create a sub string from what's in between, which in your GitHub sample would be "horacebury.github". This way your project would work on any specified domain, regardless of what sub folder it is placed in.



[TOPIC: post.html]
#7

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

The idea initially was so I could put out a demo build and have it prevent access to anywone without the required GET parameters. Easier to deploy for simple tests to those with very old phones etc.

Thanks for your help - I can see that the docs are correct but I can’t see where I went wrong with my code the first time. Of course, github samples are often better to work from anyway.

[TOPIC: post.html]
#8

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

If it helps anyone who runs across this, I've implemented a "JS lock" in my corona framework:

 

https://github.com/HoraceBury/CoronaFramework/commit/2143af6c360b52cc77c4bf668ff6144d2b61d5ac

 

It shows a message, instead of running the full app, if the URL does not include a certain parameter. The demo shows the code on the page.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: web, html, html5, build, url