How do I check my game's currant url

Get help using Construct 2

Post » Tue Oct 11, 2016 1:31 pm

Is there any way to check what's the currant url that my game is being played?

Explanation:
I have placed a game on Newgrounds and, after about 7 days, my game is being iframed on a number of different websites. The gameplays are displayed in my NG Game Statistics but not being displayed in my NG published game bar (I have over 3000 plays on NG but over 4000 plays that can't be seen apart from my private NG Game Statistics).

What I want to do is check what's the currant url of my game and if it's not: http://www.newgrounds.com/portal/view/xxxxxx then redirect to that official NG game url. Is something like that possible?
B
21
S
11
G
3
Posts: 39
Reputation: 3,365

Post » Tue Oct 11, 2016 2:18 pm

You could use the Browser object. For example, use the Browser.URL expression to check if the game is on new grounds, and the action Browser: Go to URL if it does not match. However, I dont see why you wouldnt want your game being played even if its not on its original website.
Note: I am not active anymore. If you need to reach me for one of my games, you can do so by emailing me at [email protected]
B
63
S
25
G
8
Posts: 36
Reputation: 8,443

Post » Tue Oct 11, 2016 3:35 pm

Thank you so much, just tried it and it's functioning great.

I'm o.k. with iframeing but I don't like the fact that these views are not visible in the Newgrounds game bar, just in my Game Statistics. I will use the function to open game on NG in a new window if the browser url is not identical to NG url. That way I will also have a NG gameplay-view and player can choose to play the iframed version or the NG version.

EDIT:
No, it's not working on Newgrounds. After a few tests with both unpublished and published game it seems that the function is always returning 'false' on game's url. I believe that this is happening because the game is also being iframed into newgrounds.com from uploads.ungrounded.net.
B
21
S
11
G
3
Posts: 39
Reputation: 3,365

Post » Tue Oct 11, 2016 8:41 pm

You could try your luck with a Browser.ExecJS to check the location property of the "top" window.

Code: Select all
Compare two values - Browser.ExecJS("window.top.location.toString();") <> "newgrounds url"
B
75
S
31
G
27
Posts: 1,012
Reputation: 20,759

Post » Tue Oct 11, 2016 9:41 pm

Newgrounds uses a content delivery service so there is no static url.
It will most likely change each time you upload a new version, and it will take several days before the old files are removed.
You can obtain what the current url is by opening the html source, and searching for the iframe tag.
As is you have no way to know what the url will be before you upload.
A possible solution would be a combination of @Magistross s code with a trigger to fetch the correct url from an external source that you have access to.
Image ImageImage
B
172
S
50
G
182
Posts: 8,432
Reputation: 115,083

Post » Tue Oct 11, 2016 10:03 pm

The Magistross code worked in the Construct but not on Newgrounds.
I also tried to get the url like Newt suggested but, once again, it worked in Construct (it gave me localhost) but failed in Newgrounds (gave me "0").

My capx in zip:
http://www.newgrounds.com/dump/download ... bec3e4df71
B
21
S
11
G
3
Posts: 39
Reputation: 3,365

Post » Tue Oct 11, 2016 10:25 pm

...it seems that this code worked and, unfortunately, proved that the game url is not what I need:

Code: Select all
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the URL of the document.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.URL;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

I placed it in a plain html file and uploaded it on Newgrounds, it gave me the url but it was a "http://uploads.ungrounded.net/tmp/1025000/... etc, etc".

It's of no use since I need to check the url of the active browser, not the url of the hosting service where the index.html is located.
B
21
S
11
G
3
Posts: 39
Reputation: 3,365

Post » Tue Oct 11, 2016 11:20 pm

I would suggest just sending a takedown request to the sites that are displaying the game.
Image ImageImage
B
172
S
50
G
182
Posts: 8,432
Reputation: 115,083

Post » Tue Oct 11, 2016 11:28 pm

That's a good workaround :D
...but I'm o.k. with iframeing, the game is getting nice gameplay-counts, it's just that I wanted for those views to be noted also on the main NG game page, not just in my NG developer's game statistics.
B
21
S
11
G
3
Posts: 39
Reputation: 3,365


Return to How do I....?

Who is online

Users browsing this forum: humanescape, R0J0hound, warmty and 6 guests