Is it possible to get the URL of a web build in Lua?
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?
The latter, but not in anger.
@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.
Scratch that - got it working by stripping down the CoronaLabs github demo:
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.
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.
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.
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?
The latter, but not in anger.
@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.
Scratch that - got it working by stripping down the CoronaLabs github demo:
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.
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.
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.