0 Favourites

How do I check my game's currant url

  • 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?

  • 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.

  • 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.

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

    Compare two values - Browser.ExecJS("window.top.location.toString();") <> "newgrounds url"[/code:3i5gi78c]
  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

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

    <!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>
    [/code:iu4k0njt]
    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.
  • I would suggest just sending a takedown request to the sites that are displaying the game.

  • That's a good workaround

    ...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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)